LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 08-01-2008, 12:37 PM   #1
pdonaghy
LQ Newbie
 
Registered: Aug 2008
Posts: 2

Rep: Reputation: 0
Bash sciript to edit crontab


Hi,

I want to write a bash script that edits a crontab.

For example the crontab may have mutiples entries;

***** /etc/service/start -c
***** /etc/test/test

I want to for example edit the line

***** /etc/service/start -c
to
***** /etc/service/start

and save it.

Thanks
 
Old 08-01-2008, 01:08 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can install a new crontab reading it from a file or from standard input. To modify an existing crontab you can retrieve it using option -l, then apply your changes and re-install it again. For example:
Code:
crontab -l | sed 's%/etc/service/start -c%/etc/service/start%' | crontab -
you have only to think about the editing command (sed) to apply the changes you have in mind.
 
Old 08-01-2008, 01:22 PM   #3
david1941
Member
 
Registered: May 2005
Location: St. Louis, MO
Distribution: CentOS7
Posts: 267

Rep: Reputation: 58
If you just want to edit the crontab, look up man crontab. crontab -e at the command line edits the users crontab in an editor and when one exits the editor it updates the crontab. Using this command, you preserve the permissions of the user (including root, if so invoked).

Dave
 
Old 08-04-2008, 03:30 AM   #4
pdonaghy
LQ Newbie
 
Registered: Aug 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Guys.

This works a treat;

crontab -l | sed 's%/etc/service/start -c%/etc/service/start%' | crontab -

If I want to say though replace /etc/service/start -c anything as in (.*) with /etc/service/start. So replace /etc/service/start -c and anything after that.

I'm not having much luck in getting my expression right though

Last edited by pdonaghy; 08-04-2008 at 05:15 AM.
 
Old 08-12-2008, 12:24 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here's an example:

>echo '/etc/serve/start -c'|sed 's:/etc/serve/start -c.*:/etc/service/start:'

/etc/service/start
 
  


Reply



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 doesn't let me to edit wedgeworth Linux - Software 12 12-14-2018 06:58 AM
Can't Edit Crontab rignes Linux - Software 1 04-04-2007 11:01 AM
crontab disabled after edit on solaris 5.x machines BlackHatRob Solaris / OpenSolaris 1 01-18-2007 09:13 AM
Bash Sleep vs crontab and bash serial port nutthick Programming 4 06-01-2006 02:42 AM
Using crontab in a bash script nro Linux - Newbie 3 08-26-2005 08:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 08:09 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration