Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

cron - Bash script runs manually, but fails in crontab

I have this script ftp.sh in /amadeus folder:

#!/bin/bash
. /home/thierry/.bash_profile

# constantes
HOST=xxxx
LOGIN=xxxxx
PASSWORD=xxxxxx
PORT=21

ftp -i -n $HOST $PORT << END_SCRIPT
quote USER $LOGIN
quote PASS $PASSWORD
cd www
pwd
asc
mput *.json
quit
END_SCRIPT

With the same user this command works fine:

$ . /amadeus/ftp.sh

=> a json file is well putted to the remote server.

But with this entry in crontab:

* * * * * . /amadeus/ftp.sh 2>/tmp/2.log 1>/tmp/1.log

I have files 1.log and 2.log created every second but none json file in remote server.

tmp]$ ll
-rw-r--r-- 1 thierry thierry   36 Jan 27 16:00 1.log
-rw-r--r-- 1 thierry thierry    0 Jan 27 16:00 2.log

tmp]$ more 1.log
257 "/www" is your current location

tmp]$ more 2.log
tmp]$

Thanks a lot for yours answers! Théo.

question from:https://stackoverflow.com/questions/65921862/bash-script-runs-manually-but-fails-in-crontab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Before ftp command, I had to do a "cd" to the right folder /amadeus and now it works fine!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...