comment jobs in cron for multiple accounts

Hi,

We have several jobs scheduled in cron in AIX. Before every release
we need to comment those jobs and uncomment those after the release is over.
There are several accounts whose cron entries need to be commented.
Can anyone provide me with a script which can put a '#' before each line
in each account's cron entries. I may pass the accountname as parameter
or can keep in a file and read from there and loop through. I have root and
can run with that.

Thanks in advance.

To prepend every line with an octothorpe ("#") you can use the sed-script

sed 's/^/# /' <filename>

to delete leading octothorpes use

sed 's/^# //' <filename>

Hence, a script to comment/uncomment a users sed-script would be (the following is a sketch, no effort towards error handling has been made!):

#! /bin/ksh

# run this as root. Call the script in the form
#
#     script [-c|-u] <username>
#
#    -c comment out crontab for <username>
#    -u uncomment crontab for <username>
#
#   default behavior is "-c", <username> is obligatory


typeset    chDirection="comment"
typeset    chUser=""
typeset    fTmpFile="/tmp/$$"

if [ "$1" = "-c" ] ; then
     chDirection="comment"
     shift
elif [ "$1" = "-u" ] ; then
     chDirection="uncomment"
     shift
fi

if [ $(lsuser "$1" ; print - $?) -gt 0 ] ; then
     print -u2  "The user account $1 does not exist"
     exit 1
else
     chUser="$1"
     shift
fi

if [ ! -f /var/spool/cron/crontab/${chUser} ] ; then
     print -u2 "User $chUser has no crontab file."
     exit 2
fi

if [ "$chDirection" = "comment" ] ; then
     sed 's/^/# /' /var/spool/cron/crontab/${chUser} > $fTmpFile
fi
if [ "$chDirection" = "uncomment" ] ; then
     sed 's/^# //' /var/spool/cron/crontab/${chUser} > $fTmpFile
fi
mv $fTmpFile var/spool/cron/crontab/${chUser}

exit 0

I hope this helps.

bakunin

Sounds like maybe it would be easier to set a policy that all these scripts must abort if /etc/FREEZE_SUCKER exists in the file system, or some such.

Thanks era. It worked for me.