sed and crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed and crontab
# 1  
Old 09-15-2004
sed and crontab

Hi ,

what is the simple way to do the following :

i would search in a crontab file for specific string of characters (ex: toto.ksh) and only on this line change the beginning as follows :
00 23 * * 0
with
00 23 * * 3
or maybe 2 changes:
with
10 23 * * 3

thanks in advance

Christian
# 2  
Old 09-15-2004
Hmmm.... Is it really worth (potentially) risking knackering your crontab with a script?

Why don't you just use crontab -e? (Or are you running it for a lot of users?) But to answer your question, I'd probably rather use awk than sed to modify specific fields.

Cheers
ZB
# 3  
Old 09-15-2004
Well i'm working for 2 users and about 60 servers.
I 1st send a remote script to save the crontab on each but i would apply the same modification on all of them !


but what i want could be on others types of files not only crontab !

Christian
# 4  
Old 09-16-2004
Hi ,

well i think i must associate grep and awk commands but don't know how !!!

my original text file is :

# Purge des logs et fichiers temporaires
# ------------------------------------------
00 23 * * * ksh -c '. $HOME/.kshrc;$PRCCOM/sys_purge_fic.ksh' > /tmp/sys_purge_fic_notes01.log 2>&1
#
# Lancement de commandes NOTES , fichier en entrée /users/notes01/scripts/sad/dat/notes_cmd_maint.dat
# NE PAS OUBLIER de commenter la ligne pour des commandes temporaires
#--------------------------------------------------------------------------------------------------
#
00 23 * * 3 /users/notes01/scripts/sad/util/notes_cmd_maint.ksh
#



and want to change only a part of 1 line like this :



# Purge des logs et fichiers temporaires
# ------------------------------------------
00 23 * * * ksh -c '. $HOME/.kshrc;$PRCCOM/sys_purge_fic.ksh' > /tmp/sys_purge_fic_notes01.log 2>&1
#
# Lancement de commandes NOTES , fichier en entrée /users/notes01/scripts/sad/dat/notes_cmd_maint.dat
# NE PAS OUBLIER de commenter la ligne pour des commandes temporaires
#--------------------------------------------------------------------------------------------------
#
15 23 * * 4 /users/notes01/scripts/sad/util/notes_cmd_maint.ksh
#

YES it's extracted from crontab file but i save the original one before modifying it !

thanks in advance , it would be great ! it would avoid me to modify manually 60 server's crontab !!!!!

regards

Christian
# 5  
Old 09-16-2004
For your needs, this would work...

Code:
#!/bin/sh

cp crontab crontab.old

awk '{ if ( $0 ~ /notes_cmd_maint.ksh/ ) 
	{ print "15 23 * * 4 " $6 } 
       else { print $0 } 
     }' crontab.old > crontab

exit 0

You'll need to adjust the paths to crontab to whatever suits you.

Cheers
ZB
# 6  
Old 09-16-2004
Thanks for your help !

...but if in the same line i would only modify "notes01" with "notes02" , i must use i think the BEGIN statement
but the following doesn't work !

awk '{ if ( $0 ~ /notes_cmd_maint.ksh/ )
BEGIN {FS="\/"} { print $1"/"$2"/"notes02""/"$4 "/"$5"/"$6 }
else { print $0 }
}' crontab-160904 > crontab-160904-new

exit 0



regards

Christian
# 7  
Old 09-16-2004
Include a "sub"stitute.....

Code:
awk '{ if ( $0 ~ /notes_cmd_maint.ksh/ ) 
	{ gsub( /notes01/, "notes02", $6); print "15 23 * * 4 " $6 } 
       else { print $0 } 
     }' crontab.old > crontab

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

2. AIX

Comment out crontab using sed command

I am trying to comment out the crontab entries using sed. I want to comment it out for a particular environment say '/mypath/scripts/'. Using the full path as pattern, it is working. but using variable it is not working. i have tried double quotes too. but no luck! $ crontab -l ... (3 Replies)
Discussion started by: SKhan
3 Replies

3. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

4. UNIX for Dummies Questions & Answers

HELP with crontab

I am trying to create a crontab but I keep getting a "bad minute" error. Here is what I am entering: */5****/usr/bin/php/ {path to script} After I exit the editor and save I get the following message: crontab: installing new crontab "/temp/crontab." :-2: bad minute errors in... (2 Replies)
Discussion started by: fcocnews
2 Replies

5. Shell Programming and Scripting

sed adding/removing comment in crontab

I have a requirement where I want to add a comment '#' in my crontab, run a process, than remove the '#' I added. Example cron #5,10 * * * * ls -lt /tmp 10,5 * * * * ls -lt /var I would like to be able use sed or awk to add a '#' at the begining of each line. After the command... (4 Replies)
Discussion started by: BeefStu
4 Replies

6. Shell Programming and Scripting

Sed or Awk for modify hour in a crontab AIX

Hi, I want to modifiy the hour in the crontab AIX 5.3 for this line: Input: 00 22 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 Output: 30 20 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 With the awk or sed function through a ssh -q... (1 Reply)
Discussion started by: khalidou13
1 Replies

7. UNIX for Dummies Questions & Answers

SED: Can't Repeat Search Character in SED Output

I'm not sure if the problem I'm seeing is an artifact of sed or simply a beginner's mistake. Here's the problem: I want to add a zero-width space following each underscore between XML tags. For example, if I had the following xml: <MY_BIG_TAG>This_is_a_test</MY_BIG_TAG> It should look like... (8 Replies)
Discussion started by: rhetoric101
8 Replies

8. Shell Programming and Scripting

deleting text records with sed (sed paragraphs)

Hi all, First off, Thank you all for the knowledge I have gleaned from this site! Deleting Records from a text file... sed paragraphs The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Discussion started by: Festus Hagen
1 Replies

9. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

10. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies
Login or Register to Ask a Question