comment jobs in cron for multiple accounts


 
Thread Tools Search this Thread
Operating Systems AIX comment jobs in cron for multiple accounts
# 1  
Old 04-07-2008
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.
This User Gave Thanks to shibajighosh For This Post:
# 2  
Old 04-07-2008
To prepend every line with an octothorpe ("#") you can use the sed-script

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

to delete leading octothorpes use

Code:
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!):

Code:
#! /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
# 3  
Old 04-07-2008
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.
# 4  
Old 04-08-2008
Thanks era. It worked for me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run multiple cron jobs?

I have two scripts which I'm tying to run one after the other- this is what I've tried: 00 14 * * * /path/one.sh && /path/two.sh I've also tried putting each script on a different line: 00 14 * * * /path/one.sh 00 14 * * * /path/two.sh Can this be done? (1 Reply)
Discussion started by: $shell_Learner
1 Replies

2. Shell Programming and Scripting

Shell script to run multiple jobs and it's dependent jobs

I have multiple jobs and each job dependent on other job. Each Job generates a log and If job completed successfully log file end's with JOB ENDED SUCCESSFULLY message and if it failed then it will end with JOB ENDED with FAILURE. I need an help how to start. Attaching the JOB dependency... (3 Replies)
Discussion started by: santoshkumarkal
3 Replies

3. Shell Programming and Scripting

How to View multiple Cron jobs

Hi, I ran two crontab commands using: crontab program1 crontab program2 However when I type crontab -l only the second cron job shows up, how do I see all cron jobs running and how do I edit all at the same time Thanks in Advance S:D (10 Replies)
Discussion started by: walforum
10 Replies

4. Solaris

Cron jobs and at jobs

There are two jobs in Solaris , Cron and at jobs.. I know how to disable or enable cron jobs. How can I enable at jobs and disable it. Kindly help. Rj (2 Replies)
Discussion started by: jegaraman
2 Replies

5. UNIX for Dummies Questions & Answers

Cron jobs of all accounts

Hi I want to view the schedules of all the crons under all accounts running on the UNIX server. crontab -l list the crons under my account. How to view the cron schedule of other accounts? Does it require root access? Is there a way to view the all the Crons scheduled on an UNIX server? ... (0 Replies)
Discussion started by: ashok.k
0 Replies

6. Shell Programming and Scripting

Comment/uncomment a cron

Hi, My requirement is to comment/uncomment a cron job through a script. 1. Redirected the output of crontab -l to a text file. crontab -l >cronoutput.txt 2. grep to find the script running and sed to place the comment (#) as the first char grep -i 'weblogicmonitor.sh'... (5 Replies)
Discussion started by: mannepalli
5 Replies

7. Shell Programming and Scripting

comment out a cron job as part of a script

Greetings, I am creating a ksh script to automate the installation of a utility on many servers. As part of this install, I want to check for a job in root's crontab. If the job exists, I need to comment it out. I know I will need to copy off the crontab then read it back in, but I am... (4 Replies)
Discussion started by: 22blaze
4 Replies

8. UNIX for Dummies Questions & Answers

Re : Set multiple cron jobs in one crontab file

Hello All, Hopw all is fine. I am newbie to Unix. I am using Bourne Shell (sh). One of the question I have is that I am trying to read XML file and based on reading that XML file I want to run different java programs at different hours. Meaning 05 14 * * * java ./program1 10 14 * * * java... (3 Replies)
Discussion started by: samshaw
3 Replies

9. Solaris

Cron Jobs

I'm trying to run cron jobs to start any inhibited processes after a system reboot. I can schedule th cron, but i'm confused as to how to incorporated the reboot, since reboot is scheduled at different times, once every month. How can I write this to start every 15 min after after a reboot ... (2 Replies)
Discussion started by: Remi
2 Replies

10. UNIX for Dummies Questions & Answers

cron jobs

I was wondering if itīs possible to cron job not to run on a certian day and time. Iīve got a job that runs everyday at 08:00 but would like it not to run on the 20:th between 08:00 and 10:00 Anyone know if this is possible, and if. How do i do it? regards... dOzY (3 Replies)
Discussion started by: dozy
3 Replies
Login or Register to Ask a Question