Running Dump from Cron silently fails

Running Dump from Cron silently fails









I Heart AWeber.com

Do you love AWeber, too?

The Problem

You want to use "dump" in Unix/Linux for backing up your file systems. It works fine from the command line, but silently fails in cron, even when you are using the right options and have tested it from the command line. (/sbin/dump)

For example, supposed you tested the following dump command and it works fine every time you run it on the command line as the root user:

dump -0uf /backups/root01.dump /

But, when you put it in cron for the root user, it does nothing:

5 5 * * *       /sbin/dump -0uf /backups/root01.dump /

The Solution

The dump utility is very ancient, and has some strange requirements. It expects that backups are being done interactively, and it wants to know who the user is. Cron jobs don't set the same environment variables as a normal interactive login shell, which is causing the failure. You need to set the USER and LOGNAME environment variables appropriately.

The best way to do multiple commands in Cron is to write a shell script for them, and run the shell script from cron instead:

#!/bin/sh
USER=root export USER
LOGNAME=root export LOGNAME
dump -0uf /backups/root01.dump /

There are actually 2 different things happening on the USER= line, above: variable assignment (USER=root), and an "export" command. We are allowed to put them both on the same line because in the Bourne/Bash shell, assignments cannot have any whitespace whatsoever; anything following an assignment is a completely new command. You could easily write it this way instead:

#!/bin/sh
USER=root
export USER
LOGNAME=root
export LOGNAME
dump -0uf /backups/root01.dump /

Or, for that matter, most Bourne/Bash shells support this syntax too:

#!/bin/sh
export USER=root
export LOGNAME=root
dump -0uf /backups/root01.dump /

Lets assume you named your script "backups", and put it in the /root/bin directory. Don't forget to make it executable! (chmod 755 /root/bin/backups). This makes the cron job very simple:

5 5 * * *       /root/bin/backups


Bookmark and Share


Don't miss the latest unix tips and tricks!
Subscribe to our low-volume mailing list:

Privacy Policy

See other tricks:  Web | Unix | Perl | SQL | General


Sample Sites | Customers | Our Team | Contact Us | Tips and Tricks | Tools | Our Network | Home

Copyright © 2006 Fastech Learning LLC, all rights reserved.
Phone toll free 1-866-464-6688, Phoenix Metro area 480-895-6688
Problem with this web site? please let us know