Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/ >> /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?

share|improve this question

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
share|improve this answer
Ah yes, there's lines that start write(1, ... which contain the output I was expecting. Is 1>&1 valid, would that not redirect STDOUT to STDOUT? Why does this only happen when running the script from crontab? – bbradley Feb 25 '13 at 10:44
Descriptor 1 is STDOUT. That's the default, so it's already covered by >>. If no additional descriptors are used, try moving the output redirection into the and see if that helps. – Ansgar Wiechers Feb 25 '13 at 11:28
Sorry... "moving the output redirection into the" what? – bbradley Feb 25 '13 at 11:49
You do the output redirection in the cron job. Instead of that you could modify so that the output redirection is done inside the script. Or you could write a wrapper script with the command /bin/bash /home/user/ >> /var/log/ftp-getter.log 2>&1 and then just call that wrapper script in the cron job (*/5 * * * * /home/user/ – Ansgar Wiechers Feb 25 '13 at 11:58

Redirecting from the crontab should work, but another approach you could try is to use exec within the script to redirect all output. Use it like so at the beginning of the script:

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

Now you don't need to explicitly redirect output of individual commands within the script.

share|improve this answer
Better than writing a wrapper script. Though I don't understand why some of the output of the commands in this script is suppressed when running from crontab but not when running directly. – bbradley Feb 26 '13 at 14:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.