psql:加载共享库时出错:libpq.so.5:无法打开共享对象文件:没有这样的文件或目录

时间:2017-04-06 16:23:15

标签: cron psql greenplum

我的路径变量中有psql路径。 crontab路径为usr:/usr/bin:/bin 我添加所有用户目录,然后执行cron作业。

Default PATH for usr:/usr/bin:/bin
user is:gpadmin
PATH for usr:/usr/bin:/bin:/usr/local/greenplum-db/./bin:/usr/local/greenplum-db/./ext/python/bin:/home/gpadmin/anaconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/home/gpadmin/bin

我的脚本如下(由crontab执行):

#!/bin/bash
# Usage : bash RR_load.sh

echo "Loading the data into datalake"
now="$(date +'%d-%m-%Y')"
basedir="/home/2125/RR_Dev_Code"

#echo "load started at $now"
#logname=$0"_"$now".log"
ts="$(date +'%d-%m-%Y_%H:%M:%S')"
echo "load started at $ts"
echo `who am i`
logname=$0"_"$ts".log"
echo "load started at $ts" > $logname
chmod 777 $logname
nohup python $basedir/copy_csv_to_data_lake_v3.py $basedir >> $logname
echo "process id $!" >> $logname
echo "Recreate the table using loader.sh"
echo "Default PATH for usr:"$PATH >> $logname
export PATH=$PATH:/usr/local/greenplum-db/./bin:/usr/local/greenplum-db/./ext/python/bin:/home/gpadmin/anaconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/home/gpadmin/bin
source /etc/profile
psql -h '3.48.35.24' -U 'tan12345' 'sourcing' << EOF
Select current_timestamp(0);
EOF

按照计划执行后,我在/var/spool/mail/gpadmin中看到如下消息:

Loading the data into datalake
load started at 06-04-2017_12:19:01

dos2unix: converting file /home/2125/RR_Dev_Code/sandbox-rr_data.2017-03-29.csv to UNIX format ...
Recreate the table using loader.sh
psql: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

2 个答案:

答案 0 :(得分:1)

在crontab中的命令之前添加了.bash_profile。

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

# test entry
#* * * * * echo `whoami`  > /home/2125/RR_Dev_Code/ETL/crontab.test
59 13 * * 4 . $HOME/.bash_profile;/home/2125/RR_Dev_Code/RR_load_v3.sh

感谢您在此处发布的答案: https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables

看到所有艰苦的工作现在自动运行,这样的宽慰。

答案 1 :(得分:0)

我要添加第二个答案,以防万一有人想使用除已选答案之外的其他方法。乔恩·罗伯茨(Jon Roberts)指出的解决方案效果很好。

只需运行:“源/usr/local/greenplum-db/greenplum_path.sh”

欢呼