sftp is not working in cron or crontab but ftp works fine

微笑、不失礼 提交于 2019-12-12 04:17:53

问题


i have created a script file transfer.sh which ftp a test.txt file to server, now i have made the entry of script file in crontab, if i use ftp to transfer the file it works fine in crontab, when i use sftp instead of ftp it is not working in cron tab, but when i manually run the transfer.sh script it works fine and transfer the file using sftp to the server. i don't see any error in log.

my script transfer.sh script is

sftp user/pass@host.com <<END_SCRIPT
cd /mydir
put test.txt
bye
END_SCRIPT

回答1:


crontab was not able to find sftp utility on unix server, there are two ways to resolve the problem.

  1. Append your PATH environment variable with sftp path

  2. Use sftp command with absolute path in your script

    example.

    /usr/localcw/opt/ssh/bin/sftp user/pass@host.com

how to find sftp absolute path, below is example

$which sftp
/usr/localcw/bin/sftp

go to /usr/localcw/bin location

$cd /usr/localcw/bin

hit ls -lrt sftp

/usr/localcw/bin $ls -lsrt sftp
0 lrwxrwxrwx   1 root     root          19 Apr 11  2012 sftp -> ../opt/ssh/bin/sftp

here again its a soft link to ../opt/ssh/bin/sftp, now cd to ../opt/sh/bin

/usr/localcw/bin $ cd ../opt/ssh/bin

now pwd is your sftp absolute path

/usr/localcw/opt/ssh/bin $ pwd
/usr/localcw/opt/ssh/bin

Use this path with sftp command



来源:https://stackoverflow.com/questions/33933652/sftp-is-not-working-in-cron-or-crontab-but-ftp-works-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!