- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Setting & Using Variables in 'cron'
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 04:57 AM
10-06-2005 04:57 AM
I would like to use output from the `date` command as part of a file name within the cron. I've tried about every variation I can think of and nothing is working.
Here are examples of what I'm trying to do:
* * * * * DATE=`date +%x`;/tmp/script.sh > /tmp/script_output.$DATE
or, more directly:
* * * * * /tmp/script.sh > /tmp/script_output.`date +%x`
I've tried enclosing the entire command in quotes (both " and '), parantheses, braces, etc... and nothing is working. I'm pretty sure I've done this on other versions of UNIX so maybe it's just HP's implementation of UNIX that doesn't like this?
Any help will be greatly appreciated!
Thanks,
Greg
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:01 AM
10-06-2005 05:01 AM
Re: Setting & Using Variables in 'cron'
Set your DATE in a script invoked from cron that then fires off your /tmp/script.sh.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:13 AM
10-06-2005 05:13 AM
Re: Setting & Using Variables in 'cron'
* * * * * /tmp/launcher.sh
create the /tmp/launcher.sh as follows
#!/sbin/sh
DATE=`date +%x`
/tmp/script.sh > /tmp/script_output.$DATE
save and exit
chmod 755 /tmp/launcher.sh /tmp/script.sh
(or permissions of your choice, just make sure they are executable by the owner)
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:23 AM
10-06-2005 05:23 AM
Re: Setting & Using Variables in 'cron'
* * * * * /tmp/launcher.sh /tmp/script.sh
create the /tmp/launcher.sh as follows
#!/sbin/sh
SCRIPT2RUN=$1
DATE=`date +%x`
$SCRIPT2RUN > $SCRIPT@RUN.output.$DATE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:25 AM
10-06-2005 05:25 AM
Re: Setting & Using Variables in 'cron'
$SCRIPT2RUN > $SCRIPT2RUN.output.$DATE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 05:59 AM
10-06-2005 05:59 AM
Re: Setting & Using Variables in 'cron'
I appreciate everyone's feedback.
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 06:10 AM
10-06-2005 06:10 AM
Re: Setting & Using Variables in 'cron'
* * * * * /tmp/script.sh > /tmp/script_output.$(/usr/bin/date +%m%d%y)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:35 AM
10-06-2005 08:35 AM
Re: Setting & Using Variables in 'cron'
Have you been able to get that to work on an HP-UX 11.11 server? I even tried a direct cut-n-paste and I still only get: "/tmp/script_output." with no date. It's along the lines of what I'm looking for though - all done within cron.
Thanks for the help Patrick,
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:41 AM
10-06-2005 08:41 AM
SolutionI do it all the time.
18 7 * * 1-5 /home/sys/daily > /tmp/daily_output.$(date +\%y\%m\%d)" 2>&1
You have to escape the % with the backslash. Check the man page for crontab(1).
"The sixth field, command (the balance of a line including blanks in a crontab file), is a string that is executed by the shell at the
specified times. A percent character (%) in this field (unless escaped by a backslash (\)) is translated to a newline character, dividing the field into "lines". Only the first "line" (up to a % or end-of-line) of the command field is executed by the shell. Any other "lines" are made available to the command as standard input."
Marlou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2005 08:49 AM
10-06-2005 08:49 AM
Re: Setting & Using Variables in 'cron'
Thanks for your help Marlou - it's greatly appreciated!!
Greg