Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

backup crontab

Status
Not open for further replies.

pearlofperls

Technical User
Apr 5, 2007
24
US
I'm trying to use 1 script for muliple boxes with same username to backup crontabs

Her is what I have and the problem is the hostname variable wont output to the name of the file



#!/bin/ksh


CHOST=$HOSTNAME
CDATE=`date "+%Y%m%d"`

/usr/bin/crontab -l > /mypath/home/username/crontab_bkp/${CHOST}_${CDATE}_crontab


OUTPUT:

-rw-rw-r-- 1 username users 7885 Apr 22 21:13 _crontab_20100422


 
I presume the $HOSTNAME variable is not defined; it's not a standard variable that you can assume is defined.

Try using this instead, which uses the hostname command to get it:

Code:
CHOST=$(hostname)

Annihilannic.
 
Why have a script? Try putting this as a crontab entry...
Code:
0 1 * * 0 /bin/crontab -l > /mypath/home/username/crontab_bkp/`/bin/hostname`_`/bin/date +\%Y\%m\%d`_crontab 2>&1
That will back up the current crontab with the name you are wanting, every Sunday at 1am.

No script needed. It's all right there. You just need to include full paths to everything, and escape the percent signs, since they are a special character to [tt]cron[/tt].


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top