Cron Job Config files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron Job Config files
# 1  
Old 12-09-2008
Cron Job Config files

Hi All,
I have created 2 shell scripts and set Cron jobs which runs it at various frequencies.The first one which runs every 2 minutes Monday to Friday and another cron job runs at 11PM on the last Sunday of every month. I have given the cron job entries below.

Was wondering whether instead hard coding the parameter values meant for the shell script in the crontab whether it was ok to set them as unix level environment variable or something and then use them instead in the cron job.

I think it will make the cron job make cleaner as well as more easily manageable.

My DBA says to use a “config” file to contain all the parameters that I need to pass on to the script

What are your thoughts on this?.If I have to go the config file way, what do i need to do as i have don't know much about creating/updating config files...

Code:
#======================================================================================
# CRON JOB FOR RUNNING THE SHELL SCRIPTS
#======================================================================================
# ------------- minute (0 - 59)
# | ----------- hour (0 - 23)
# | | --------- day of month (1 - 31)
# | | | ------- month (1 - 12)
# | | | | ----- day of week (0 - 6) (Sunday=0)
# | | | | |
 */2 * * * 1-5 sh SHELL1.ksh <PARAM1> <PARAM2> <PARAM3> <PARAM4> <PARAM5> <PARAM6> <PARAM7> <PARAM8> <PARAM9> <PARAM10> <PARAM11>
23 * * * 0 [`date "+%d"` -gt 24] && sh SHELL2.ksh <PARAM1> <PARAM2> <PARAM3> <PARAM4> <PARAM5> <PARAM6> <PARAM7> <PARAM8> <PARAM9> <PARAM10> <PARAM11>

# 2  
Old 12-09-2008
Just greate a file:
param1=value1
param2=value2
.....
source that file within your script
Code:
#!/bin/anyshell
......
. path/file

#and you can access the variables within your scripts
echo $param1
# 3  
Old 12-09-2008
Quote:
Originally Posted by demwz
Just greate a file:
param1=value1
param2=value2
.....
source that file within your script
#!/bin/anyshell
......
. path/file

#and you can access the variables within your scripts
echo $param1

Hi,
thanks for the reply.I see what you are saying.But my issue is slightly different.My shell script takes 11 params and the shell script is run as a cron job.So instead of hard coding the values of the 11 parameters in the crontab file is there a way out to refer then from a file or something?..similar to the one you told me...such as setting the parameter values in the a cfg file and referring them in the crontab?
Thanks
# 4  
Old 12-09-2008
Ok.I have placed all the paremeters as variables in a filecalled as CONFIG.cfg and assigned them the relevant values.

Then I have added this portion to the top of my crontab
#! . /path/CONFIG.cfg

But my cron does'nt seem to run..I am very new to Unix so please bear my ignorance
# 5  
Old 12-10-2008
dont add the line to your crontab. add it to your scripts
# 6  
Old 12-10-2008
Hi,
thanks very much and it worked.
Now another question:

How do I migrate this crontab of mine across various environments?
My colleague says it has to be manually typed into various unix boxes.Can't we have a script/file that we can install or place in a certain path so that we can eliminate manual typing of crontab entries?

Thanks
V
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks. Not sure if it makes a... (1 Reply)
Discussion started by: DavidHoffman
1 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

4. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

5. UNIX for Advanced & Expert Users

cron job to extact lines from files to another file and ftp to new server

i have a text file in this format: which creates a new one everyday in the form of filename _zing__r200_2012_8_10_log.txt Fri Aug 10 07:29:17 EDT 2012, usera(192.168.0.245) to anotheruser: hey top, this is a private test Fri Aug 10 07:29:28 EDT 2012, anotheruser(192.168.0.245) to usera: got... (2 Replies)
Discussion started by: bkkid
2 Replies

6. Shell Programming and Scripting

Script that will be a cron job to export rrd files for cacti server

I wrote a quick little script that will eventually end up as a cron job to export rrd files for my cacti server. Here is the script: #!/bin/bash rm -rf /backup/cacti_xml/* cd /var/www/html/rra ls -1 *.rrd | awk '{print "rrdtool dump "$1" > /backup/cacti_xml/"$1".xml"}' | sh -x Is there... (5 Replies)
Discussion started by: TheBigAmbulance
5 Replies

7. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

8. UNIX for Dummies Questions & Answers

Cron job to delete files

Hi everyone! I'm sorry, I'm a total noob but would really appreciate any advice or help. I want to create a cron job that would run every hour and would look inside a few different folders. If any new files were created within those folders within the last hour they would be destroyed, but any... (2 Replies)
Discussion started by: jessn
2 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. Shell Programming and Scripting

CRON-Job / Shell-Skript deleting special files

Just I'm trying to find script, which will do the following job: 1. as a CRON-Job it shoult a) delete files which will be either older than 24 hours or b) all files within a) a directory deleting recursive b) only a special directory. 2. write an error-/Delete_log... (9 Replies)
Discussion started by: ManfredWL
9 Replies
Login or Register to Ask a Question