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

psql: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

我的路径变量中有 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=[=12=]"_"$now".log"
ts="$(date +'%d-%m-%Y_%H:%M:%S')"
echo "load started at $ts"
echo `who am i`
logname=[=12=]"_"$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

在 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.

现在自动看到所有的辛勤工作 运行 真是如释重负。

我正在添加第二个答案,以防万一有人想使用与已选择的答案不同的方法。 Jon Roberts 指出的解决方案非常有效。

刚刚 运行: "source /usr/local/greenplum-db/greenplum_path.sh"

干杯