crontab:“找不到ftp命令";macos 中的错误 [英] crontab: "ftp command not found" error in macos

查看:41
本文介绍了crontab:“找不到ftp命令";macos 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是新手.我一直在寻找有关此问题的解决方案,但似乎找不到.

Newb here. I've been looking for solutions about this but I can't seem to find one.

来自我的 crontab 的错误日志:

/Users/harrold/bin/ftp_automate.sh: line 14: ftp: command not found

我制作了一个名为 ftp_automate.sh 的脚本,将文件从我的本地文件夹发送到我的 ftp 服务器.该脚本在终端(zsh) 中使用 % sh ftp_automate.sh 工作.这是脚本:

I have made a script named ftp_automate.sh sending files to my ftp server from my local folder. The script works in terminal(zsh) with % sh ftp_automate.sh. Here's the script:

#!/bin/bash
# FTP server details here
SERVER="ftp.DUMMYSITE.com"
USERNAME="DUMMYUSER"
PASSWORD="DUMMYPASS"

# local directory containing source backup file
SOURCEFILES="/Users/harrold/Desktop/FOLDER/ftp-test"

# remote server directory path in which backup needs to be put in
BACKUPDIRCTORY="/folder/subfolder"

# login to remote server
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD
cd $BACKUPDIRCTORY
bin
lcd $SOURCEFILES
mput *
quit
EOF

但是,我希望它使用 crontab 工作,因此它每分钟都能完成这项工作.这就是我用 % crontab -e 做到的:

However, I want it to work using crontab so it does the job every minute. This is how I did it with % crontab -e:

* * * * * /Users/harrold/bin/ftp_automate.sh >> /Users/harrold/bin/logs/ftp.log 2>&1

知道为什么我收到 ftp 命令未找到错误吗?

顺便说一下,我的脚本放在 /Users/harrold/bin 中.

By the way, my script is placed inside /Users/harrold/bin.

推荐答案

我现在知道了!

我只需要在我的脚本中添加 ftp 的完整路径,如下所示:

I just had to add the full path of ftp on my script, as in:

/usr/local/bin/ftp -n -i $SERVER <<EOF

此外,我必须在我的 bash 配置文件中添加 ftp $PATH vi .bash_profile 在我的主目录(例如/Users/harrold)

And additionally, I had to add ftp $PATH on my bash profile vi .bash_profile on my home directory (e.g. /Users/harrold)

export PATH="/usr/local/bin/ftp:$PATH"

为了使更改生效,我必须使用 source ~/.bash_profile

For the changes to take effect, I had to reload my profile with source ~/.bash_profile

这篇关于crontab:“找不到ftp命令";macos 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆