Problem with script arguments in crontab


 
Thread Tools Search this Thread
Operating Systems HP-UX Problem with script arguments in crontab
# 1  
Old 11-23-2010
Problem with script arguments in crontab

I have a script scheduled in cron as shown below.

16 12 * * * /users/mydir/bin/process_master.ksh `date '+%Y%m%d'` >> /users/mydir/process_master.out

This script executes correctly when invoked on command line, but doesn't work the same when scheduled in crontab. Crontab is working fine with other scripts which don't have arguments passed. In this case, for some reason the date command is not getting evaluated correctly.

Even if --> `date '+%Y%m%d'` <--- is included in double quotes it justs returns null.

Any advise or suggestions please ?

Last edited by mk1216; 11-23-2010 at 10:02 AM..
# 2  
Old 11-23-2010
Try these date formats:
Code:
$(date +\%Y\%m\%d)

or:
Code:
$(date '+%Y%m%d')

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 11-23-2010
Thanks very much for the quick post.

I tried this option -> $(date +\%Y\%m\%d) and it worked fine.

On the same lines I tried escaping the % in my original command and that worked as well..

The cron entry is now like ..and works fine !!

16 12 * * * /users/mydir/bin/process_master.ksh `date +\%Y\%m\%d` >> /users/mydir/process_master.out


But do we know what could have been the problem, is it just the way cron evaluates command options ?
# 4  
Old 11-23-2010
Quote:
Originally Posted by mk1216
Thanks very much for the quick post.

I tried this option -> $(date +\%Y\%m\%d) and it worked fine.

On the same lines I tried escaping the % in my original command and that worked as well..

The cron entry is now like ..and works fine !!

16 12 * * * /users/mydir/bin/process_master.ksh `date +\%Y\%m\%d` >> /users/mydir/process_master.out


But do we know what could have been the problem, is it just the way cron evaluates command options ?
Unless escaped with a backslash (\) percent-signs (%) in the command will be interpreted as newline characters.
This User Gave Thanks to Franklin52 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C shell script passing arguments problem.

I found something insteresting when I tested passing arguments into my scripts. My scripts is as below. % cat passarg.env #!/bin/csh echo "passarg: argv = $argv argv = $argv" passarg1.env $* % cat passarg1.env #!/bin/csh echo "passarg1: argv = $argv argvp=$argv" set str = "test... (5 Replies)
Discussion started by: bestard
5 Replies

2. Solaris

Script problem when running on crontab

Hi guys! I created a backup script that works fine when I run manually, but when I put a crontab job to execute it the result are not the expected. (not a time problem). Here is my script: bash-3.00# cat /bk_tool/backup2.sh #!/usr/bin/csh clear set DIR_HOST='SCP08' ... (3 Replies)
Discussion started by: andredemartini
3 Replies

3. UNIX for Dummies Questions & Answers

Problem with a script in crontab

Hi guys, I have a shell script which i have put on crontab to run every min. Problem is that is isn't running. But if i run the script from the existing location it runs perfectly. but if i got out of the directory and run it giving the path. it doesn't work. sh script_name.sh ----... (3 Replies)
Discussion started by: nick1982
3 Replies

4. Shell Programming and Scripting

Problem with perl script on crontab

Hi everybody, I have a perl script. I want to run it as a cron job every 10 minutes. I insert the command into crontab , using crontab -e. The problem is, I didnt get any output from script inside crontab, whereas when I run it manually through 'perl myscript.pl' it running well. Here is the cron... (2 Replies)
Discussion started by: franzramadhan
2 Replies

5. Shell Programming and Scripting

Problem passing arguments to a Python script

I have part of the script below and I tried calling the script using ./tsimplex.py --fstmod=chris.cmod --nxz=8x6 --varp=0.25 but am getting the error option --fstmod must not have an argument Any idea on how to fix this would be highly appreciated #! /usr/bin/python import... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Problem with crontab running a script

I am trying to use the CRON utility in Fedora 11 & CentOS... I intend to run a script which pops up a warning message every hour and i made the following entry using "CRONTAB -e " * * * * * sh /bin/myscript.sh But this does not seem to be running. Another thing to note is that,... (4 Replies)
Discussion started by: Vabiosis
4 Replies

7. Linux

Problem with crontab + bash script

Crontab: 16 14 * * * /root/bin/./empty_mail.sh >> /root/bin/log.txt L=`mailq |grep -c frozen` echo "${NUMMAIL} frozen mail to be removed from the mailq" #echo "Press Enter to continue" #read CONTINUE echo -en "-> " for i in `mailq | grep frozen | awk '{print $3}'` ; do exim4 -Mrm $i... (1 Reply)
Discussion started by: wessberg
1 Replies

8. UNIX for Dummies Questions & Answers

Variable problem in script when using crontab

Hi, this is my first shell script. Anyway i am trying to ftp files from one machine to another. The name of the script is ifsftp_orabkp. The code is as follows: HOST="122.122.122.22" USER="ftp_ftp" PASSWD="ftp.222222" Y1=`(perl -e '@y=localtime(time());printf... (11 Replies)
Discussion started by: dazz
11 Replies

9. Shell Programming and Scripting

problem passing arguments to script

Hi, I am writing a script, which is invoked from other system using ssh. I have problems reading the arguments passing to the script. If the argument has a space in it (ex "rev 2.00"), the script considers "rev" as 1 argument and "2.00" as another. Instead i want "rev 2.00" to be considered... (5 Replies)
Discussion started by: cjjoy
5 Replies

10. Solaris

Unix script Problem with crontab

Hi Experts, Am facing some problems with script (Sun solaris 9). My script (sqlplus.sh)looks like this. . . ............................................... set 'date' dd=$3 export dd mon=$2 export mon yyyy=$6 export yyyy cd /oracle/P47/saparch... (8 Replies)
Discussion started by: vrjalli
8 Replies
Login or Register to Ask a Question