sftp不工作在cron或crontab,但ftp工作正常 [英] sftp is not working in cron or crontab but ftp works fine
问题描述
我已创建一个脚本文件 transfer.sh
其中 ftp
a test.txt
文件到服务器,现在我已在 crontab
中输入脚本文件,如果我使用 ftp
在crontab中传输文件,它工作正常,当我使用 sftp
而不是ftp它不工作在cron选项卡,但是当我手动运行transfer.sh脚本运行正常,并使用 sftp
将文件传输到服务器。我在日志中没有看到任何错误。
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.
我的脚本 transfer.sh
脚本是
sftp user/pass@host.com <<END_SCRIPT
cd /mydir
put test.txt
bye
END_SCRIPT
推荐答案
crontab无法要在unix服务器上找到 sftp
实用程序,有两种方法可以解决此问题。
crontab was not able to find sftp
utility on unix server, there are two ways to resolve the problem.
-
将
PATH
附加sftp
路径
在脚本中使用带有绝对路径的sftp命令
Use sftp command with absolute path in your script
示例。
/ usr / localcw / opt / ssh / bin / sftp user/pass@host.com
/usr/localcw/opt/ssh/bin/sftp user/pass@host.com
如何查找 sftp
绝对路径,下面是示例
how to find sftp
absolute path, below is example
$which sftp
/usr/localcw/bin/sftp
转到 / usr / localcw / bin
location
go to /usr/localcw/bin
location
$cd /usr/localcw/bin
点击 ls -lrt sftp
/usr/localcw/bin $ls -lsrt sftp
0 lrwxrwxrwx 1 root root 19 Apr 11 2012 sftp -> ../opt/ssh/bin/sftp
这里再次是一个软链接 ../ opt / ssh / bin / sftp
,现在 cd
到 ../ opt / sh / bin
here again its a soft link to ../opt/ssh/bin/sftp
, now cd
to ../opt/sh/bin
/usr/localcw/bin $ cd ../opt/ssh/bin
现在pwd是您的 sftp
绝对路径
now pwd is your sftp
absolute path
/usr/localcw/opt/ssh/bin $ pwd
/usr/localcw/opt/ssh/bin
使用sftp命令使用此路径
Use this path with sftp command
这篇关于sftp不工作在cron或crontab,但ftp工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!