shell中使用curl命令定时上传日志文件到服务器并清理,放在crontab中发生异常

时间:2022-09-14 07:59:55
如题,在shell中使用curl命令进行上传,单独执行时并未发生任何错误,但是放在crontab中进行定时执行时发生错误, 有部分日志文件上传但是大部分未成功上传,只是上传了一部分,不完整,而且打印跟踪发现 curl命令返回141错误,经过查资料知道141属于curl命令内部错误,不是用户名密码、IP端口之类的错误。很捉急,求大神指导。。。
shell部分脚本如下:

#....
filelist=`find -mmin +$clean_time`
for file in $filelist
do
if [ -f $file ];then
filename=`echo $file | cut -b 3-`
curl -T $file -u $username:$password --ftp-create-dirs ftp://$remote_host_ip:$remote_host_port/$remote_dir/$filename
exec_s=$?
if [ "$exec_s" = "0" ];then
rm -f $file
cur_time=`date +%Y-%m-%d//%H:%M:%S`
echo "[$cur_time]:[$filename]...............[ok]"
elif [ "$exec_s" = "7" ];then
echo "[error]:cannot connect to host,please check remote ip address or port is correct.........[error]"
continue
elif [ "$exec_s" = "67" ];then
echo "[error]:access denied,please check username and password is correct.............[error]"
continue
elif [ "$exec_s" = "26" ];then
echo "[error]:cannot open file.............[error]"
continue
elif [ "$exec_s" = "9" ];then
echo "[error]:failed upload file,please check remote directory is correct...........[error]"
continue
else
echo "[error]:[$file] upload failed,have not know the reason.............[error]"
continue
fi
fi
done
#....



补充:好像每次都是成功上传了11个文件之后,curl命令都会报141错误,不知道为什么。。。
      单独运行脚本所有文件均能成功上传。

4 个解决方案

#1


curl的错误表里面也没有141号错误啊,没看到你把错误号打印出来啊。

#2


调试的时候打印的,贴出来的是原来的脚本
在上面第8行后面添加:
echo $exec_x
打印看到输出141错误的

#3


Curl returned 141 - it is result of a segfault which means it's Curls fault.
Try again and if it crashes more than a couple of times you either need to
reinstall Curl or consult with your distribution manual and contact support.

查到141错误时这么说的。。郁闷

#4


汗,偶都是用lftp上传的,没用curl玩过ftp的路过……

#1


curl的错误表里面也没有141号错误啊,没看到你把错误号打印出来啊。

#2


调试的时候打印的,贴出来的是原来的脚本
在上面第8行后面添加:
echo $exec_x
打印看到输出141错误的

#3


Curl returned 141 - it is result of a segfault which means it's Curls fault.
Try again and if it crashes more than a couple of times you either need to
reinstall Curl or consult with your distribution manual and contact support.

查到141错误时这么说的。。郁闷

#4


汗,偶都是用lftp上传的,没用curl玩过ftp的路过……