LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-13-2008, 12:49 PM   #1
inderpunj
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Rep: Reputation: 0
removing # from crontab (bash script)


Hi All,

I am new to scripting. i am creating a script by which it will check all the enteries in crontab and will remove # if any entry will be commented. Please help me to resolve out.
For exp :-
$crontab -l
#*/10 * * * * ./aa.sh
* * * * * ./bb.sh
# * * * * * ./cc.sh

I want to remove # so that the crontab -l should like this :-

*/10 * * * * ./aa.sh
* * * * * ./bb.sh
* * * * * ./cc.sh

Please help me.
Thanks in advance
Inder
 
Old 10-13-2008, 01:07 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,778

Rep: Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625
Quote:
Originally Posted by inderpunj View Post
Hi All,

I am new to scripting. i am creating a script by which it will check all the enteries in crontab and will remove # if any entry will be commented. Please help me to resolve out.
For exp :-
$crontab -l
#*/10 * * * * ./aa.sh
* * * * * ./bb.sh
# * * * * * ./cc.sh

I want to remove # so that the crontab -l should like this :-

*/10 * * * * ./aa.sh
* * * * * ./bb.sh
* * * * * ./cc.sh

Please help me.
Thanks in advance
Inder
Check the sed command. Run the file through sed, and remove the "#", such as "sed 's/\#//g'"
 
Old 10-13-2008, 01:18 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,151

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Read man sed, and add something like sed s/^[[:space:]]*#// where you want to un-comment a line.

Note that sed normally takes a file as input, so something like sed s/^[[:space:]]*#// /etc/crontab > /etc/crontab.new might work.

You might also think about removing empty lines and trailing comments.
 
Old 10-13-2008, 01:20 PM   #4
inderpunj
LQ Newbie
 
Registered: Oct 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
Check the sed command. Run the file through sed, and remove the "#", such as "sed 's/\#//g'"
Many Thanks for your help

How can i run this command through a script so that it will reflect all the enteries in crontab ?
Thanks
Inder
 
Old 10-13-2008, 02:34 PM   #5
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,778

Rep: Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625Reputation: 2625
Quote:
Originally Posted by inderpunj View Post
Many Thanks for your help

How can i run this command through a script so that it will reflect all the enteries in crontab ?
Thanks
Inder
If you read the man page on SED, or look at any of the Google hits you'd get, you'd see the 'g' at the end of the statement, means to replace all occurrences.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab/bash: a console script to make just a 2-3 sec ring to a fixe phone ? frenchn00b Programming 10 04-27-2008 01:37 PM
bash script to rename files removing one character Byenary Linux - Newbie 2 04-08-2008 10:12 AM
Bash script not running within crontab job WrightExposure Linux - General 3 01-23-2007 06:28 PM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 08:04 PM
bash script for database searching using crontab saurya_s Linux - Software 5 01-22-2004 08:53 AM


All times are GMT -5. The time now is 08:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration