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
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.
$ 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
$ sed "/\/mypath\/scripts/s!^!#!" cron.backup > newCron.sample