Saturday, August 18, 2012

I edited cron tab for user , its didnt save in crontab ,whats the reason ?

i edited cron tab for user , its didnt save in crontab ,whats the reason ?




How you edit it? DIrectly edit cron file? or via crontab command?


USE EDITOR =vi editor 
then modify
Before, backup the cron file first. 

If you want to edit directly, make sure you stop and start cron daemon. 

If you do crontab -e , make sure you set TERM and EDITOR first. Good 
practice to stop and start cron daemon. 

o make life easier, you could use a script like so (which I have called 
editcrontab) to ensure a backup of the users' cron is always made before 
and after a change:- 

#!/usr/bin/ksh 

# Optional (and not recommended) environment over-rides (which really 
should be set in /etc/profile or ~/.profile) 
EDITOR=/usr/bin/vi 
TERM=vt220 

if [ ! -n "$1" ]; then 
USER=$LOGNAME 
else 
USER=$1 
fi 

# Make pre-change backup 
crontab -l $USER > `/usr/xpg4/bin/awk -F\: -v user=$USER '$1 ~ user { 
print $6 }' /etc/passwd`/crontab.`date '+%Y%m%d-%H%M%S'`.before 
# Make required changes 
crontab -e $USER 
# Make post-change backup 
crontab -l $USER > `/usr/xpg4/bin/awk -F\: -v user=$USER '$1 ~ user { 
print $6 }' /etc/passwd`/crontab.`date '+%Y%m%d-%H%M%S'`.after 

# end of script 


0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM