Centos – shell script in crontab, not all output being logged

bashcentoscronftpshell-scripting

I've got a simple shell script that runs a few LFTP commands and processes the files.
When running straight from bash I get full output of those LFTP commands on screen.

When running from crontab with the following…
*/5 * * * * /bin/bash /home/user/ftp-getter.sh >> /var/log/ftp-getter.log 2>&1
I only get the output of lines where I am explicitly echoing some output and the output of the date command. The text returned by LFTP doesn't go into the log.

I've tried moving the 2>&1 to before the >> and still get the same result.

When running that crontab command straight from the command line I do get the LFTP output both on screen and in the log file. But not when running in crontab.

Is there something special about the output from LFTP that would cause this and that might apply to other commands when running from a shell script in crontab?

Best Answer

lftp might be using file descriptors other than STDOUT and STDERR. Check by running the command in strace

strace lftp ...

and look for lines starting with "write":

write(3, ...

The number is the descriptor that the program writes to. Redirect that descriptor as well.

... >> /var/log/ftp-getter.log 2>&1 3>&1