Crontab update


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab update
# 8  
Old 04-25-2018
No, I don't think anyone has said that it cannot be done using a tool/editor/script automatically. The decision is whether to use crontab command in a script or use another tool to edit the crontab directly followed by a restart of the cron daemon.
# 9  
Old 04-25-2018
You still haven't described the "conditions" you mentioned in post #1 in this thread and you still haven't said how you would like to tell your script what you want it to do on a particular invocation. Without this information, I don't see how we can suggest a script that will do what you want.

Note that although you can't easily run vi with a script, you can easily run ed with a script. So your script might want to consider using:
Code:
EDITOR=ed crontab -u user -e <<-EOF
	ed commands to add/remove # from appropriate lines
EOF

but the ed commands you put in that here-document will depend on what "conditions" have been detected, how you want to tell your script which country codes to enable and/or disable, etc.

If you're not comfortable writing ed commands (which you should be if you're used to running vi), you can also use:
Code:
crontab -u user -l > tempfile
use whatever commands you want to update tempfile
contab -u user tempfile
rm tempfile

to make the changes take effect immediately without stopping and restarting cron. (As hicksdb8 mentioned, if you directly edit the user's crontab file in place not using crontab -e and not using crontab file, the changes might not be noticed by cron until the next time you reboot or stop and restart cron.)
# 10  
Old 04-26-2018
sorry for the delayed response . here is the sample rows from the file we have


Code:
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh ca kreight v1 monitor >> /u/application/grpms/ca/logs/kreight/v1/startkreight.out 2>&1
 
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh us kreight v2 monitor >> /u/application/grpms/us/logs/kreight/v2/startkreight.out 2>&1

The above 2 rows one for Canada and other for USA. In this case I need to comment out USA and enable the crontab and also we have done all the migrations we need to uncomment the same . We have more than 250 rows in the file . How would this can be achieved using a script .

Last edited by ron5174; 04-26-2018 at 02:35 PM.. Reason: Corrected CODE tags
# 11  
Old 04-26-2018
It can be solved in hundreds of ways based on the code snippets that I have already shown you. If you won't tell us how you plan to tell your script which country code(s) are to be enabled and/or which country codes are to be disabled, I am not going to attempt to enumerate hundreds of ways that I might imagine doing what you seem to want to do. Everything you should need to do this on your own was given to you (with two different approaches) in post #9 in this thread.

Until you clearly describe how you plan to interact with your script, I'm not willing to waste any more time trying to help you. Please answer the questions that have been asked in this thread and, then, we might be able to help you.

Note also that in your earlier posts country codes were shown in upper-case letters, but in post #10 the country codes turned out to be lower-case letters. You need to clearly specify how country codes and/or names will be given to your script and whether the country codes in your crontab file are upper-case, lower-case, or mixed-case.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 12  
Old 04-26-2018
Apologies for my wrong file entries provided earlier . Following is the sample file with all the countries
ca-> Canada
us-> usa
mx -> mexico
gb-> Great Britain
cn -> China
ge -> germany

Code:
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh ca kreight v1 monitor >> /u/application/grpms/ca/logs/kreight/v1/startkreight.out 2>&1
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh us kreight v1 monitor >> /u/application/grpms/us/logs/kreight/v1/startkreight.out 2>&1
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh mx kreight v1 monitor >> /u/application/grpms/mx/logs/kreight/v1/startkreight.out 2>&1
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh gb kreight v1 monitor >> /u/application/grpms/gb/logs/kreight/v1/startkreight.out 2>&1
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh cn kreight v1 monitor >> /u/application/grpms/cn/logs/kreight/v1/startkreight.out 2>&1
0-59 * * * * . /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh ge kreight v1 monitor >> /u/application/grpms/ge/logs/kreight/v1/startkreight.out 2>&1

We need to disable(comment out) country USA & enable all of the other countries when we are making application changes for USA. Once USA application chnages are completed, then we are planning to uncomment the cron entry for USA and once everything looks fine , we will go for the next country application changes . The only thing we need to see here , one country entries will be commented at a given time .

Let me if any further information required .

Thanks
Ron T

Last edited by MadeInGermany; 04-27-2018 at 04:31 AM.. Reason: Added code tags
# 13  
Old 04-27-2018
How about one static crontab entry that runs a script?
Code:
0-59 * * * * sh /path/to/script

And the /path/to/script has the commands
Code:
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh ca kreight v1 monitor >> /u/application/grpms/ca/logs/kreight/v1/startkreight.out 2>&1
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh us kreight v1 monitor >> /u/application/grpms/us/logs/kreight/v1/startkreight.out 2>&1
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh mx kreight v1 monitor >> /u/application/grpms/mx/logs/kreight/v1/startkreight.out 2>&1
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh gb kreight v1 monitor >> /u/application/grpms/gb/logs/kreight/v1/startkreight.out 2>&1
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh cn kreight v1 monitor >> /u/application/grpms/cn/logs/kreight/v1/startkreight.out 2>&1
. /u/data/environment;export ENV=prod;/u/application/pkms/startStoppry.sh ge kreight v1 monitor >> /u/application/grpms/ge/logs/kreight/v1/startkreight.out 2>&1

And now you only need a command to change the script file.
This User Gave Thanks to MadeInGermany For This Post:
# 14  
Old 04-27-2018
The script file could even be parameter driven / controlled...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

How to update Solaris 10 Update 3 to Update 11?

Hi friends, We have a Solaris machine running 10 update 3 -bash-3.2# cat /etc/release Solaris 10 11/06 s10s_u3wos_10 SPARC Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms. ... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Red Hat

RedHat 5 update 9 BASH update issue

Hi i want to update the BASH because of the "shell shock" vulnerability. my RedHat 5 is clean install with the default mirror site. when im running the command: yum update bash im getting a message saying there is no update. you can see in the attach picture... what am i doing wrong? is... (4 Replies)
Discussion started by: guy3145
4 Replies

3. Programming

MYSQL - trigger update on record insert or update

Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works: UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` ); So now I want this... (5 Replies)
Discussion started by: barrydocks
5 Replies

4. Solaris

Is it possible to "upgrade" Sol10 update 9 to update 10?

Is it possible to "upgrade" Sol10 update 9 to update 10 by booting from the DVD? I had never even tried this until a user asked me to do it, so i tried and it just hung there after the part where it reads the rules.ok file. Is this even possible to upgrade? or does it have to be a new install. ... (5 Replies)
Discussion started by: BG_JrAdmin
5 Replies

5. Solaris

Install update 6 on solaris with update 3

I want to update my solaris 10 server which is currently on update 3 stage. A new application require it to be on update 6. What is the best way to make it update 6. should i just install the patch or should i go for the liveupgrade?? thanks for you help in advance (3 Replies)
Discussion started by: uxravi
3 Replies

6. UNIX for Dummies Questions & Answers

How to get the last crontab

Hi all, can anybody tell how to get the last crontab if it is deleted. is there any way to get the crontab back? or it will it be staored anywhere ? its very urgent, can anybody help for the same? Thanks, Vinay (5 Replies)
Discussion started by: vinayakatj56
5 Replies

7. UNIX for Advanced & Expert Users

Pro*C Update not working from Crontab

Dear All, I have writen a Pro*c program that does a data base select,insert,update statements and I have scheduled the program to run from crontab, It is runing fine for the select insert and commit statement till it reaches the update statement , it throws the following error: SQL On IPB... (2 Replies)
Discussion started by: alhallay
2 Replies

8. UNIX for Dummies Questions & Answers

UNIX "Crontab update"

Is there another location to update a cron that's run daily. I have updated the root cron located "/var/spool/cron/crontabs " After the update the cron doesn't run at the new time it was set at. It continues to run at the old time. Checking the root cron after it has been updated show the... (3 Replies)
Discussion started by: ddrivera
3 Replies

9. Solaris

Unable to update the Crontab

Hi Everyone, Each time I do update the crontab, it gets reset after exiting from the telnet session. I'm using Solaris 2.8 So it goes like this: Step 1: Login as root, from a telnet session Step 2: Crontab -e (I make modification) Step 3: Save and exit Step 4: Type crontab -l , changes... (4 Replies)
Discussion started by: Jeremy3
4 Replies
Login or Register to Ask a Question