Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates and cron 1

Status
Not open for further replies.

KenCunningham

Technical User
Mar 20, 2001
8,475
GB
Hi. I'm trying to figure out a method of passing today's date as a parameter to a script run through cron. I've tried the following command:

'<path_to_script> -u <param1> -p <param2> -d '`date +%d-%b-%y | tr -s '[:lower:]' '[:upper:]'`

Ignore param1 and param2, these seem to work, but the -d date parameter doesn't evaluate to today's date. As you can see, I am attempting to append the date command to the end of the command string, but cron doesn't appear to like it. I have also tried using /usr/bin/date rather than date alone, to no effect.

Any ideas gratefully received.
 
Looks like you have an extra quote...

'<path_to_script> -u <param1> -p <param2> -d [highlight]'[/highlight]`date +%d-%b-%y | tr -s '[:lower:]' '[:upper:]'`
 
Sorry Ken, I see what you're doing now. Maybe try double quotes around it all...

"<path_to_script> -u <param1> -p <param2> -d `date +%d-%b-%y | tr -s '[:lower:]' '[:upper:]'`
 
Thanks Ygor, I'll give it a go. Unfortunately as this is only a once a week job, I'll not be able to test fully until mid week. I'll post back once I have. Have a good weekend in the meantime.
 
Using $(...) instead of `...` makes it better readable:
Code:
<p_t_s> -u <p1> -p <p2> -d $(date +%d-%b-%y | tr -s [:lower:] [:upper:])
I don't need quotes around [:(upper|lower):].
For testing you could use another script.

seeking a job as java-programmer in Berlin:
 
Thanks Stefan. Yes, I could probably try another script, but in all honesty I've got enough going on just now! I'll let you know the outcome.
 
Ken,
I think the problem is with the % sign in your command. It has a special meaning to cron; man crontab for details.
So try to mask it with \%.
hth
 
Hoinz - eureka! That's it. Teach me to read the crontab man page more careful in future!!
 
...not to mention being more careful how I spell carefully!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top