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

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

问题描述

Newb在这里.我一直在寻找解决方案,但似乎找不到.

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天全站免登陆