Bash: Different behaviour when executed via cron

From FVue

Jump to: navigation, search


Contents

Problem

When a bash program is executed via cron, it has no terminal connected to stdin/stdout. For instance, I experienced dar to return a different exit status unless the -Q option was specified.

Solution

Test the program via the batch command. This batch command executes commands just like cron – with no terminal connected, but at a later time when system load levels permit. Using batch saves you the hassle of modifying crontab for just a test-run.

Example

$> batch
warning: commands will be executed using /bin/sh
at> touch /tmp/now~  
at> ^D
$> ls -l /tmp/now~
-rw-r--r-- 1 user group 0 2007-11-15 21:26 /tmp/now~
$> 

See also

At and Batch - Red Hat Documentation
Thorough information about at and batch, more than info batch
Personal tools
Google