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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command line crontab editing

Status
Not open for further replies.

linmac

Technical User
Aug 21, 2002
7
MY
hi all,

i got crontab file like this:

50 1 * * * * /usr/local/bin/script1
50 2 * * * * /usr/local/bin/script2
50 3 * * * * /usr/local/bin/script3
..
..
.. and more.

question:-

1) how from shell script file, i add # to line 1 and line3 in first run?

2) remove # from line 1 and line 3

what i want is one script that check if line 1 and line 3 have comment (#). if got, the script remove the # and if no add the comment. 2 function in one script. can anybody help me on this? thanx in advance.
(maybe using sed or awk, either one)


 
Here's an awk script to do it

{
if (NR==1 || NR==3) {
if (!sub(/^#/,"")) $0 = "#" $0
}
print
}

CaKiwi
 
cp file xxfile
#1.loop (insert #):
sed -e '1s/.*/#&/;3s/.*/#&/' xxfile >file
#2.loop (remove #):
sed -e '1s/#*\(.*\)/\1/;3s/#*\(.*\)/\1/' xxfile >file
# check if worked
[ -s file ] && rm xxfile || mv xxfile file

#PS: if you modify crontabs using scripts
#do it properly, checking owner and perms
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top