Cronjob setting

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Cronjob setting
# 1  
Old 03-19-2012
Cronjob setting

Hi there

There's a script I would like to run daily every 5 minutes and this job should restart every 12:03AM so it would append to a new file with the following day date format instead of running and updating continuously into one log. I am not sure of the syntaxing, what I did was to set it to run daily 1-31..any idea on how to set it to run every 5 mins and refresh at 12:03 am?

Code:
##Run memory report every 5 mins daily
*/5 * 1-31 * * /usr/local/bin/MEM_Report/MEM_daily_run

Well, it doesn't have to be exactly 12:03 AM, its just that I want a new report with the following day's date format

I was thinking of
Code:
 */5 0-23 * * *

maybe I should wait out till tomorrow so I can see how the reports come out..I started the script just now..cron confuses me every time Smilie

Last edited by hedkandi; 03-19-2012 at 01:52 AM.. Reason: corrections
# 2  
Old 03-19-2012
what is the contents of your script?
maybe you can set name of the log as today's date (or yest) in script instead of job reset.
# 3  
Old 03-20-2012
Hi there ygemici

I did the second setting of */5 23 * * * and that gave me a new report this morning at 11 am...so whys that! I want it to start at midnight..
Code:
[root@espcrmtestapp 03]# ls -lrt
total 956
-rw-r--r--. 1 root root 512101 Mar 19 23:55 2012-03-19
-rw-r--r--. 1 root root 453702 Mar 20 11:00 2012-03-20

This is the script

Code:
#!/bin/bash

##Run Daily MEM report

MEM_REPORT="/var/log/MEM_Report/$(date +'%m')"

MEM_DAILY="/var/log/MEM_Report/$(date +'%m')/$(date +'%F')"

cd ${MEM_REPORT}

ps aux| sort -k4 -r | head -10 >> "${MEM_DAILY}"


Last edited by hedkandi; 03-20-2012 at 12:05 AM.. Reason: added code
# 4  
Old 03-20-2012
because midnight is zero, not 23
# 5  
Old 03-20-2012
So if I were to run the cron every 5 minutes and refresh at midnight, how do I do it?
# 6  
Old 03-20-2012
What timezone are you in when you are at the command prompt?
Code:
echo $TZ
date

And can you make a one-off test cron to find out the value of $TZ and the value of date when running from cron.


Please also post what Operating System and version you have.
# 7  
Old 03-20-2012
Quote:
Originally Posted by hedkandi
Hi there ygemici

I did the second setting of */5 23 * * * and that gave me a new report this morning at 11 am...so whys that! I want it to start at midnight..
Code:
[root@espcrmtestapp 03]# ls -lrt
total 956
-rw-r--r--. 1 root root 512101 Mar 19 23:55 2012-03-19
-rw-r--r--. 1 root root 453702 Mar 20 11:00 2012-03-20

This is the script

Code:
#!/bin/bash

##Run Daily MEM report

MEM_REPORT="/var/log/MEM_Report/$(date +'%m')"

MEM_DAILY="/var/log/MEM_Report/$(date +'%m')/$(date +'%F')"

cd ${MEM_REPORT}

ps aux| sort -k4 -r | head -10 >> "${MEM_DAILY}"

hi hedkandi,
your script is seem OK.
but as already mentioned by @methly, system date settings and cron may use different timezone information(TZ).
check if your system (redhat derivative )
Code:
# cat /etc/crontab

or solaris
Code:
# grep ^TZ /etc/TIMEZONE

check your user's profile file that runs this cronjob
both of them are differ?


add the cronjob maybe like this
Code:
*/5 * * * * /usr/local/bin/MEM_Report/MEM_daily_run

Code:
 # cat /usr/local/bin/MEM_Report/MEM_daily_run
#!/bin/bash
## MEMORY USAGE SCRIPT
LOGF="/var/log/MEM_Report" ; cd "$LOGF" &>/dev/null || exit 1
if [ ! -d "$(date +'%m')" ] ; then
mkdir $(date +'%m');cstat=$?
else cstat=0 ; fi
if [ $cstat -eq 0 ] ; then
MEM_DAILY="$(date +'%m')/$(date +'%F')"
echo -e "\t\t\t [$(date "+%F] -->  %02k:%M:%S")">>"$MEM_DAILY"
ps aux| sort -k4 -r | head -10 >>"$MEM_DAILY"
echo "">>"$MEM_DAILY"
else
echo "Check Permission on the $LOGF folder!!"
exit 1
fi

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cronjob

How to set cronjob for 48 hours. I can set for 2 days as shown below. * * */2 * * It is creating confusion for 30 days & 31 days per month. (3 Replies)
Discussion started by: Nishit
3 Replies

2. Solaris

Is there a difference between setting a user as nologin and setting it as a role?

Trying to figure out the best method of security for oracle user accounts. In Solaris 10 they are set as regular users but have nologin set forcing the dev's to login as themselves and then su to the oracle users. In Solaris11 we have the option of making it a role because RBAC is enabled but... (1 Reply)
Discussion started by: os2mac
1 Replies

3. UNIX for Advanced & Expert Users

Help with cronjob setting

Hi everyone, I have set a cronjob to run every 5 minutes. But this has to be stopped between 1:00AM to 3:00AM. How do I do it? (3 Replies)
Discussion started by: VidyaVenugopal
3 Replies

4. UNIX for Dummies Questions & Answers

cronjob

Is the cronjob below can run only first wednesday of every month? 30 5 1-7 * 3 command please tell me (3 Replies)
Discussion started by: Anjan1
3 Replies

5. UNIX for Dummies Questions & Answers

Cronjob help

Hi I am very new to linux. I want to run a cronjob every 15 minutes that checks a directory for files. If the directory contains more than ten files I want it to send an email to me. All I have is this... */15 * * * * ls -l | wc -l | | mail -s "This is just a test" I would... (2 Replies)
Discussion started by: LinuxNewb
2 Replies

6. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

7. Fedora

Setting up Cronjob

Hi, I had to setup some cron jobs using crontab -e when logged in as root. I noticed that the jobs only run when the permissons on the shell script file are set to execute on root and other. Why does "other" have to have its execution permission set? (6 Replies)
Discussion started by: mojoman
6 Replies

8. Shell Programming and Scripting

Cronjob

Hi, I'm totally new to shell scripting. I need help in my crontab script. I'm trying to read some values from user (username, log file directory, server) and then use those value to create a crontab for log rotation after some interval of time. creating crontabs manually isn't big deal.... (11 Replies)
Discussion started by: MisterKhan
11 Replies

9. Solaris

at vs cronjob

HI, What is the differnece between at / con job? thanks in advance. (1 Reply)
Discussion started by: mokkan
1 Replies

10. Shell Programming and Scripting

Cronjob

Please can someone help me. I need to set up a cron job to measure CPU usage, Disk I/O and memory usage over a period of 1 minute along with the number of users logged into the system. I also need to send it to another user besides myself every hour. Please can someone help me! Thanks. (4 Replies)
Discussion started by: gerwhelan
4 Replies
Login or Register to Ask a Question