Operating System - HP-UX
1753804 Members
7642 Online
108805 Solutions
New Discussion юеВ

Re: $(date +%d%m%y) in CRON JOBS

 
arkie
Super Advisor

$(date +%d%m%y) in CRON JOBS

Hi All,

Want to check on the growth of a particular file. Last week - this file ($ORACLE_HOME/network/log/listener.log) led to a FS full situation and subsequently SAP users were unable to log in to the system.

I have added a cronjob to record the file size at a regular interval (for testing - at 1 min interval now ... later will try to tap at say 7 pm day end)

The "crontab -l" output is :-

* * * * * ll /oracle/N11/920_64/network/log/listener.log > /tmp/listmon/listener_$(date +%d%m%y).out

My idea was to create a new file at the end of the specified interval to hold the output. But, the output file was created as ...

listener_

and the content is getting overwritten every time.

My query is - why is the $(date +%d%m%y) part not working ?
5 REPLIES 5
Raj D.
Honored Contributor

Re: $(date +%d%m%y) in CRON JOBS

Arkie,


Check this out:

1. Test it:
# DATE="`date +%H%M.%m%d%y`"
# touch file.$DATE




2.Use in crontab:
So the crontab would be like below:,


* * * * * ll /oracle/N11/920_64/network/log/listener.log > /tmp/listmon/listener_`date +%H%M.%m%d%y`.out




Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
R.O.
Esteemed Contributor

Re: $(date +%d%m%y) in CRON JOBS

Hi,

You can create a script like this:

#!/bin/sh
DATE=$(/sbin/date +%d%m%y)
ll /oracle/N11/920_64/network/log/listener.log > /tmp/listmon/listener_$DATE.out

Give execution permission to the script and execute the script through cron.

Regards,
"When you look into an abyss, the abyss also looks into you"
Dennis Handly
Acclaimed Contributor

Re: $(date +%d%m%y) in CRON JOBS

>why is the $(date +%d%m%y) part not working?

% is a special char to crontab, it is a line break char. You need to quote each one, "\".
TwoProc
Honored Contributor

Re: $(date +%d%m%y) in CRON JOBS

Another possible: When running a script in cron - not much of the environment is set. There is a good chance that "date" is not in the path of the shell that is being run.
Therefore, add the full path to the beginning of the date command:
ex: $(/usr/bin/date
instead of
$(date

I don't know the full path to the data command, and the example above is just a guess, you'll have to figure out where the date command actually lives.

We are the people our parents warned us about --Jimmy Buffett
Dennis Handly
Acclaimed Contributor

Re: $(date +%d%m%y) in CRON JOBS

>John: There is a good chance that "date" is not in the path of the shell that is being run.

No, date(1) is in the default path:
PATH=/usr/bin:/usr/sbin:.