Visit Our UNIX and Linux User Community


Modify crontab file on many hosts...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify crontab file on many hosts...
# 1  
Old 10-15-2009
Question Modify crontab file on many hosts...

Hi everyone taking a second to read this Smilie,

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!!! Smilie


Brian
# 2  
Old 10-15-2009
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  
Old 10-15-2009
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  
Old 10-15-2009
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.

Previous Thread | Next Thread
Test Your Knowledge in Computers #996
Difficulty: Medium
Major Unix vendors, including Sun Microsystems, HP, IBM, and SGI, have been selling virtualized hardware since before 1990.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

How to copy a tar file on a series of remote hosts and untar it on those hosts?

Am trying to copy a tar file onto a series of remote hosts and untar it at the destination. Need to do this without having to do multiple ssh. Actions to perform within a single ssh session via shell script - copy a file - untar at destination (remote host) OS : Linux RHEL6 (3 Replies)
Discussion started by: sankasu
3 Replies

2. Shell Programming and Scripting

How to synchronise a file to 2 different hosts?

Hello, We ve got 2 sites (Site1, Site2), joined thanks vpn. We had 2 differents files with a list of all host in each sites. Server1 has list1.ini, and Server2 has list2.ini everyone from Site1 update list1.ini by ssh or script to Server1 everyone from Site2 update list2.ini by ssh or... (1 Reply)
Discussion started by: cterra
1 Replies

3. UNIX for Dummies Questions & Answers

Modify hour crontab UNIX

Hello, I wish to modify the day of launch of a "batch" in the crontab on several servers with awk or sed. Can you help me ? Beforehand thank you 00 18 * * 1 /box/Pra/bin/systeme_reverse.ksh -s >/dev/null 2>&1 (7 Replies)
Discussion started by: khalidou13
7 Replies

4. Shell Programming and Scripting

Checking crontab job entry in 3 different hosts

Hi Gurus, I am trying to connect to remote host from current host to check crontab entries. I have started like this ssh -n -l db2psp 205.191.156.17 ". ~/.profile >/dev/null 2>/dev/null; cd log ;ls | wc -l" I got this error ? ssh: connect to host 205.191.156.17 port 22:... (1 Reply)
Discussion started by: rocking77
1 Replies

5. AIX

aix tcp wrappers hosts.allow hosts.deny?

hi all just installed the netsec.options.tcpwrapper from expansion pack, which used to be a rpm, for my aix 6.1 test box. it is so unpredictable. i set up the hosts.deny as suggested for all and allow the sshd for specific ip addresses/hostnames. the tcpdchk says the hosts allowed and... (0 Replies)
Discussion started by: wf201626
0 Replies

6. UNIX for Dummies Questions & Answers

Hosts file

What are the xid and cid numbers in a host file used for on solaris? If possible can I get a detailed link on the configuration of hosts file explaining xid and cid. :o (1 Reply)
Discussion started by: usm4n
1 Replies

7. Shell Programming and Scripting

Sed or Awk for modify hour in a crontab AIX

Hi, I want to modifiy the hour in the crontab AIX 5.3 for this line: Input: 00 22 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 Output: 30 20 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 With the awk or sed function through a ssh -q... (1 Reply)
Discussion started by: khalidou13
1 Replies

8. UNIX for Dummies Questions & Answers

HOSTS File

Hi All, I am to the UNIX world and want to know if I can specify a range of IP addresses instead of having to include one by one on the HOSTS file. Can I just say 127.20.1.1 to 127.20.1.156 ? Or the only way is to put one by one along with the machine name next to the IP ? THANKS (4 Replies)
Discussion started by: cymerman
4 Replies

9. UNIX for Dummies Questions & Answers

hosts.allow & hosts.deny

Hi! Im trying to use host.allow & host.deny to resrtic access to my sun machine, but it doesnt seem to work... I want to allow full access from certain IPīs (ssh,http,ftp,etc...) but deny all kind of conections from outsideworld, the way that im doing that is: hosts.allow ALL:127.0.0.1... (2 Replies)
Discussion started by: Sorrento
2 Replies

10. UNIX for Dummies Questions & Answers

Using a script to modify the crontab

I want to add one line to the end of my crontab using a script. I have tried piping in the editor commands, but I can't get it to work. crontab -e user << EX $a This is the text I want to add. . wq EX This doesn't work. Is there an easier way to do this? (2 Replies)
Discussion started by: johnmsucpe
2 Replies

Featured Tech Videos