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

adding "#" to each line 1

Status
Not open for further replies.

haux

Programmer
Apr 11, 2001
79
DZ
Hi every one,

How to write script that will add "#" in the begening of each line of my crontab ?

And how to wrtite a script that will delete all the "#" added from the begening of each line in my cron ?

Thank you.

 
If you want to stop all jobs from running, IMHO it is better to

- copy the crontab file somewhere safe
- remove the crontab file

Then afterwards:

- install the crontab file again from the safecopy

(to copy/remove)
mkdir -p /var/crontabs_bu
DTTM=$(date +'%Y%m%d%H%M%S')
crontab -l >/var/crontabs_bu/crontab.${LOGNAME}.${DTTM}
(make a remote copy also, whatever suits you)
crontab -r

(to reinstall)
crontab /var/crontabs_bu/crontab.${LOGNAME}.yyyymmddHHMMSS (choose a file that is saved here)




HTH,

p5wizard
 
hi,

I am using this solution but I want to learn how to add and remove caracteres in the begening of files.

Thx
 
crontab -e then
Code:
:%s/^/\#/
explanation
:%s - on all lines substitute
/^/ - at the beginning of the line
/\#/ - hash symbol
Note that the # has to be escaped.

Ceci n'est pas une signature
Columb Healy
 
Note that by simply editing a crontab file, you won't stop cron jobs from happening. You need to stop/start cron in order to re-read the crontab files or find another way to have cron re-examine the crontab files...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top