Comment out crontab using sed command


 
Thread Tools Search this Thread
Operating Systems AIX Comment out crontab using sed command
# 1  
Old 10-09-2013
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!

Code:
$ crontab -l

0,20,40 * * * * /mypath/scripts/script1.sh
15,35,55 * * * * /mypath/scripts/script2.sh
5,15,25,35,45,55 * * * * /somepath/somedirectory/script3.sh

$ PATTERN=/mypath/scripts

$ crontab -l > cron.backup
$ sed "/${PATTERN}/s!^!#!" cron.backup > newCron.sample

$ crontab newCron.sample

I have also tried to escape the '$' and the braces also.

Code:
$ sed "/\${PATTERN}/s!^!#!" cron.backup > newCron.sample

$ sed "/\$\{PATTERN\}/s!^!#!" cron.backup > newCron.sample

None of the above is working. but if I use the following code, its working absolutely fine

Code:
$ sed "/\/mypath\/scripts/s!^!#!" cron.backup > newCron.sample

# 2  
Old 10-09-2013
I'd say it doesn't like the / chars in PATTERN. Try to escape them; execute with set -vx
# 3  
Old 10-09-2013
Thanks RudiC !
I am not familiar with the use of 'set' and could not find any suitable example too. Could you please elaborate on the same?
# 4  
Old 10-09-2013
You could also use either "|" or "\\" as a sed limiter,
actualy "," would be possible too - but not in this case.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

One Line Command how to use pipe statements to execute and comment on multiple possible outcomes

Hello Forum, I'm looking to expand the following command: INACTIVE_KERNELS=$(python -mplatform | grep -qi red && rpm -qa | grep '^kernel-' |grep -vE `uname -r` | paste -sd \; || echo "Not Red Hat Server") Currently this command will check if my server is RedHat server using the grep -qi... (6 Replies)
Discussion started by: greavette
6 Replies

2. Shell Programming and Scripting

sed/awk script to replace only FIRST comment in the file

My first comment on every file contains the license message. I want to replace with a new license message. I used the below sed script, which replaces all comments. What is the modification or any other method with awk script for the below to edit only the first comment(license message)? #sed -f... (1 Reply)
Discussion started by: vpshastry
1 Replies

3. Shell Programming and Scripting

sed escape character for comment string "/*"

Good afternoon all, I'm hoping my newbie question can help bolster someone's street_cred.sh today. I'm trying to "fingerprint" SQL on its way into the rdbms for a benchmarking process (so I can tie the resource allocation back to the process more precisely). To do this, I'm essentially... (4 Replies)
Discussion started by: toeharp
4 Replies

4. 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

5. Shell Programming and Scripting

Comment a line with SED

I have around 25 hosts and each hosts has 4 instance of jboss and 4 different ip attached to it . I need to make some changes to the startup scripts. Any tips appreciated. I have total of 100 instances which bind to 100 different ip address based on instance name. For example File1 ... (1 Reply)
Discussion started by: gubbu
1 Replies

6. Shell Programming and Scripting

Using sed to comment out line in /etc/vfstab

I am running a script remotely to do the following 1. Kill all processes by a user 2. Uninstall certain packages 3. FTP over a new file 4. Kill a ldap process that is not allowing my /devdsk/c0t0d0s7 slice to un-mount 5. Unmount /h 6. comment out the slice in vfstab 7. newfs the... (9 Replies)
Discussion started by: deaconf19
9 Replies

7. Shell Programming and Scripting

Help using SED to comment XML elements

I'm trying to write a script to help automate some VERY tedious manual tasks. I have groups of fairly large XML files (~3mb+) that I need to edit. I need to look through the files and parse the XML looking for a certain flag contained in a field. If I find this flag (an integer value) I need... (4 Replies)
Discussion started by: J-Hon
4 Replies

8. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

9. Shell Programming and Scripting

sed/awk to insert comment at defined line number

Hi there, may someone easily help me on this : I want to insert a text in a specific line number like : linenumb2start=`cat memory_map.dld | nl -ba | egrep -i "label" | cut -f1` line2insert=`expr $linenumb2start + 2` and now I need to replace something like {} with {comment} at... (8 Replies)
Discussion started by: homefp
8 Replies

10. Shell Programming and Scripting

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 (7 Replies)
Discussion started by: Nicol
7 Replies
Login or Register to Ask a Question