The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
range in hosts file daveisme AIX 4 12-11-2008 11:42 AM
FTP file to different hosts coolkid Shell Programming and Scripting 4 08-06-2008 06:41 PM
HOSTS File cymerman UNIX for Dummies Questions & Answers 4 01-19-2007 12:26 PM
Using a script to modify the crontab johnmsucpe UNIX for Dummies Questions & Answers 2 07-07-2005 02:44 PM
dns and hosts file rmuhammad IP Networking 4 11-12-2003 02:46 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-15-2009
Casey's Avatar
Casey Casey is offline
Registered User
  
 

Join Date: Jun 2009
Location: Buenos Aires
Posts: 18
Question Modify crontab file on many hosts...

Hi everyone taking a second to read this ,

I need to modify a line from the root crontab file... Usually, if I need to do this I use the crontab -e, which opens up the file with Vi, then I edit it and there's no problem.

Now, I need to do this but on many servers at the same time... Like in 200. I know how to execute the script on them all, but what I'm thinking about is how can I modify these crontab files, since as far as I know it's kinda unhealthy to directly modify them from /var/spool/cron/crontabs/root. So I can't use my sed/awk commands over these files...

My idea is to run the little script from a NIM on all servers.

Any suggestion?


Thanks in advance!!!


Brian
  #2 (permalink)  
Old 10-15-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
crontab can also accept a file argument, just crontab filename, to replace the current cron table with the contents of filename. crontab - will read from standard input instead of a file. If you're appending something to a crontab, something like:
Code:
crontab -l > /root/cron-backup-$$
(       cat /root/cron-backup-$$
        echo "# Comment line for new entry"
        echo "0 2 * * * /path/to/command argument" ) | crontab -
might work. Use caution of course.
  #3 (permalink)  
Old 10-15-2009
Casey's Avatar
Casey Casey is offline
Registered User
  
 

Join Date: Jun 2009
Location: Buenos Aires
Posts: 18
Hi Corona,

That's nice. I didn't know I could tell crontab to use another file.
I don't have to append anything, actually, I have to modify (not add) a line in the middle of the crontab file, which I would do using sed/awk.

So I can copy /var/spool/cron/crontabs/root (the current crontab file) to /var/spool/cron/crontabs/root.new and then run

Code:
crontab /var/spool/cron/crontabs/root.new
And that should work fine, I even still have the old root crontab file in case something goes wrong.
Am I right?
I'm sorry, I just want to make sure I won't have to work all night long since alot of servers will be affected, hahaha.

Thanks a lot!


Brian
  #4 (permalink)  
Old 10-15-2009
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 427
it would be best to avoid directly manipulating files in /var/spool/cron/crontabs/. create a backup with crontab -l as Corona688 suggested and then install the new one via the crontab command. Don't store the backup in /var/spool/cron/crontabs.
Reply

Bookmarks

Tags
awk, crontab, modify, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0