passing date parameter in cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing date parameter in cronjob
# 1  
Old 09-17-2008
passing date parameter in cronjob

Hi All,

I have a crontab entry for every 5 min running.

5 * * * * /tmp/scripts/ksh/CsVues_H.sh `date +%Y%m%d_%H` >> /tmp/scripts/ksh/Cronresult.log

and I am passing the date parameter. ( `date +%Y%m%d_%H` )

But the parameter values which i am expecting inside the script is somethinglike "20080910_12". But iam getting values like "Wed Sep 17 12:35:47 CEST 2008"

How can i convert the values like "20080910_12" ? (in AIX Machine)

Thanks and Regards
This User Gave Thanks to scorpio For This Post:
# 2  
Old 09-17-2008
Can you not place the date command inside the script itself?
# 3  
Old 09-17-2008
No.
Because some times i need to run the scripts mannualy also with differnt times ...
# 4  
Old 09-17-2008
Try to escape the % in the date format:

Code:
5 * * * * /tmp/scripts/ksh/CsVues_H.sh $(date +\%Y\%m\%d_\%H) >> /tmp/scripts/ksh/Cronresult.log

Or use quotes:

Code:
5 * * * * /tmp/scripts/ksh/CsVues_H.sh $(date '+%Y%m%d_%H') >> /tmp/scripts/ksh/Cronresult.log

Regards
# 5  
Old 09-17-2008
Or maybe cron has a PATH which picks up a really old version of date which doesn't even understand the +%xxx stuff. Can you add an explicit path to the correct date command? (Maybe write a wrapper script which calculates the date and sets up the redirection, so that what you invoke from crontab is just the name of the wrapper script and nothing too complex.)
# 6  
Old 09-17-2008
I don't know AIX, but I do know there are some ancient shells out there. The default shell for cron is usually /bin/sh. That could be part of the problem as Franklin notes. However, finding a root cause may or may not solve the problem - I'm all for workarounds in cases like this, because cron can be pain in the butt.

Create a second wrapper script with a decent shell
Code:
#!/usr/bin/ksh  
# start_CSVues.sh
/tmp/scripts/ksh/CsVues_H.sh $(date +\%Y\%m\%d_\%H) >> /tmp/scripts/ksh/Cronresult.log
exit $?

Put start_CsVues.sh in the crontab. I'm with era on this it is not worth the time to debug.
# 7  
Old 09-17-2008
Hi All,

I tried Franklin's code

5 * * * * /tmp/scripts/ksh/CsVues_H.sh $(date +\%Y\%m\%d_\%H) >> /tmp/scripts/ksh/Cronresult.log

Its working ....

And thanks to all for the help ....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing parameter through file

Hi , I am passing date parameter through file my shell script testing.sh is #set -x #set -v asd=$1 asd1=$2 echo $asd echo $asd1 Passing parameter as below sh testing.sh `cat file1.txt` Output (2 Replies)
Discussion started by: kaushik02018
2 Replies

2. Shell Programming and Scripting

Passing parameter more than 9

Hi, I've written a script where eleven parameter to be passed from command line which is inserting into an oracle table, it is working but the tenth and 11th parameter are not accepting as given it is referring to 1st parameter. HERE IS THE SCRIPT #!/bin/ksh #set -o echo $*... (4 Replies)
Discussion started by: sankar
4 Replies

3. Shell Programming and Scripting

Passing parameter and option together

Hi , How can I pass option and parameter together? I want like script.sh par1 par2 -s option1 And when I am doing echo $1 echo $2 #opt is the variable where we are storing the option value through getops echo $opt output should be (4 Replies)
Discussion started by: Anupam_Halder
4 Replies

4. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

5. UNIX and Linux Applications

Passing date parameter on Kshell command line

I need to execute a .ksh from command line. The ksh calls a control file and has 3 parameters. First parameter is a csv file, second the target table in oracle and third parameter is a date parameter. I am attempting the below from the ksh command line {code} => testfile.ksh filname.csv... (1 Reply)
Discussion started by: kobe24
1 Replies

6. Shell Programming and Scripting

Passing a parameter to AWK

Hi All, I am trying to pass a parameter to AWK on my KSH shell prompt as below. var1=2 echo $var1 awk -v var2=${var1} '{print var2}' testfile.txt I am passing the input file (testfile) to awk to get some o/p. It is having 10 records. When I run AWK, it is throwing the following errors... (1 Reply)
Discussion started by: Raamc
1 Replies

7. Shell Programming and Scripting

Parameter Passing problem

Hi All, I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths. In the script i am validating the number of paramaters it received as below #-------------------------------------- # Check Command line arguments... (8 Replies)
Discussion started by: Raamc
8 Replies

8. Solaris

passing an input parameter like date thru jcl using BPXBATCH utility

Hi.... i need to pass the dates (from - to) as the input parameters thru jcl invoking BPXBATCH utility. I know that PARM will do the above functionality. But how the above dates passed through jcl will be linked in the java-db2 program to be used in sql queries in order to generate the report... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

9. Shell Programming and Scripting

Passing Date as parameter with sh script

Hi I need to pass a date argument with my shell script. Can any one send me code for the same. eg For 15th Aug 2006. Iwant to pass parameter like this ./startenv.sh 08/15/2006. Everyday date argument must change. Will the below code work ? ./startenv.sh date '+%m/%d/%y' THanks... (1 Reply)
Discussion started by: pankajkrmishra
1 Replies

10. Shell Programming and Scripting

parameter passing

Hallo everyone, This is my problem below: /home/cerebrus/pax=>vat class2.sh ksh: vat: not found /home/cerebrus/pax=>cat class2.sh #!/bin/ksh set -x bdf|grep appsdev|awk '{ print $5 }'> class3 dd={cat class3} echo $dd /home/cerebrus/pax=> /home/cerebrus/pax=>./class2.sh + bdf +... (8 Replies)
Discussion started by: kekanap
8 Replies
Login or Register to Ask a Question