Search code examples
bashcron

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.


Solution

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