我是Linux的新手,我有带有脚本ftp.sh
的linux服务器,它将文件传输到Windows服务器。
我试图在PUTTY / winSCP中通过crontab命令每天06:15安排它
15 06 * * * sh ftp.sh
并收到此错误消息:
command not found
我还尝试使用
从Windows批处理文件安排它start folderName\putty.exe -ssh root@10.*.*.* 22 -pw "password"
登录成功,但无法执行导航到/opt/dan/scripts
或在其中执行sh ftp.sh
命令。
我做错了什么?还有其他我想过的方法吗?
答案 0 :(得分:1)
sh无法执行ftp.sh,因为ftp.sh可能不在PATH环境变量中。如果你写完ftp.sh的完整路径,你可能会成功。
15 06 * * * sh /the/path/to/ftp.sh
或取决于您的设置
15 06 * * * / path / to / sh /the/path/to/ftp.sh
或者
15 06 * * * /the/path/to/ftp.sh
答案 1 :(得分:1)
您的操作系统似乎无法识别' sh'作为一个命令,如下所述:
command not found
这通常意味着它没有安装在您正在使用的Linux的特定风格上。您应该使用不同的文件解释器,或者如果您确定“' sh'安装然后你应该在cron命令中使用该程序的绝对路径。
如果您在终端会话中键入以下内容,则应显示完整路径:
whereis sh
或者:
which sh
答案 2 :(得分:0)
详细了解PATH variable。它在交互式shell中是不一样的(它们通常在~/.bashrc
)和cron作业中设置。
因此,在ftp.sh
中为crontab
shell脚本指定一个绝对路径,然后使用shebang #!/bin/sh
启动该脚本,如pubspec.yaml