Extracting time from Crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting time from Crontab
# 1  
Old 08-15-2008
Extracting time from Crontab

Hi,

I am a beginner in shell scripting but I have a task to complete where I have to extract the time of script execution in human format so anyone can run the script and understand what script is running when in simple format. Let me illustrate what I mean:

Two scripts in crontab, for this illustration:

1 0 * * * /usr/bin/rotatelogs.pl
5 3,9,15,18,22 * * * /usr/scripts/backupDB.ksh

Now, how would I translate 0 in first line to say "00:01 AM" and same for second line translating it to "03:05 AM", "09:05 AM", "03:05 PM", " 06:05 PM", "10:05 PM".

Any help is greatly appreciated and if you think there is an excellent source to learn on the shell scripting, on the web or a book please advice.

Thanks in advance!!
HS
# 2  
Old 08-15-2008
Quote:
Originally Posted by harjitsingh
Any help is greatly appreciated and if you think there is an excellent source to learn on the shell scripting, on the web or a book please advice.
HS
Advanced Bash-Scripting Guide
# 3  
Old 08-15-2008
Thanks Broli, I have that link and working on it. It is a wonderful guide for a beginner or advanced scripter.
But any one have clue how to convert the numbers to time format?
thanks,
hs
# 4  
Old 08-15-2008
Assuming the first field(minutes) is not having commas and no starts in first two fields. Also it doesn't take care of the days if you have any. Probably you can work on that :

crontab -l | grep -v '^$' | grep -v '^#' |awk '{ gsub(/[ ]*,[ ]*/, ","); print }' | awk '{printf("%s,%02d,%s\n", $6,$1,$2)}' | awk -F, '{printf("%s runs at : ",$1);for(i=3;i<=NF;i++){printf("%02d:%02d, ", $i,$2)} printf "\n" }'

Also, I think you can easily work on formatting and converting to AM/PM.

Last edited by sudhamacs; 08-15-2008 at 06:08 PM..
# 5  
Old 08-19-2008
Thanks, that is enough to get me started...I appreciate your guidance...Thx!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crontab does not kick at the given time

I have crontab set to be triggered daily @ 8 am and 8:20 am server time. 00 08 * * * /web/scripts/check.sh 20 08 * * * /web/scripts/check.shuname -a Linux mymac 3.10.0-327.36.3.el7.x86_64 #1 SMP Thu Oct 20 04:56:07 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux ls -ltr /web/scripts/check.sh... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. UNIX for Dummies Questions & Answers

Extracting substring between pattern only one time

Hello ifconfig return : eth0 Link encap:Ethernet HWaddr 11:24:1D:C1:99:BA inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:37307 errors:0 dropped:0 overruns:0 frame:0 ... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Solaris

Please help why my Crontab is not running on time?

I have set up my cron job on the solaris SunOS 5.10 Generic_138888-03 sun4u sparc SUNW,UltraAX-i2 but it is not running on time as expected. Would you please help me to find out what I did wrong? I want to have this cron job run once every month on the 1st Wednesday of the month, but it ran... (6 Replies)
Discussion started by: ggcc
6 Replies

4. Shell Programming and Scripting

extracting data from file using time stamp

Hi Guys ! is it possible to extract lines from a file which satisfy a time contraint for example program should consider two boundaries one current time and second the user define time and then extract all those line which fall into that specified time lets say 10 (user define time) and 12... (5 Replies)
Discussion started by: ourned
5 Replies

5. Shell Programming and Scripting

crontab time

good day..how can I simply create a cron job that will be executed every 5mins from 12:01 to 7Pm.. is it like this */5 12:01-19 * * * <path> (3 Replies)
Discussion started by: lhareigh890
3 Replies

6. UNIX for Dummies Questions & Answers

Extracting a Time Span from Syslog Messages File

Hi all, I need your help to explain how I can extract a time span from the syslog messages file on a Solaris 10 system. Here is an example extract of the syslog messages: Dec 4 11:51:38 hajap141-0107.nls.jlrint.com 267938: Dec 4 11:51:36: %DOT11-6-DISASSOC: Interface Dot11Radio0,... (4 Replies)
Discussion started by: wthomas
4 Replies

7. Shell Programming and Scripting

Extracting date & time from file name

Hi, I am having a file name as exp_bkp_tables_18_Oct_2010_10_50_28.dmp which is used for import the records. Now, I want to print the output using the selected file name as below : Table records will get restored as on date 18-Oct-2010 and time 10:50:28 How it can be done ? With... (5 Replies)
Discussion started by: milink
5 Replies

8. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

9. Shell Programming and Scripting

Extracting date-time from file.

I have the following file and need to extract date and time part for each record. Pl. could anyone provide an shell script which could be used to do it. Here is the file: /rgrdev/pdsud2/unx/agc/src/agcmst: /rgrsrc/pdspms/unx/agc/src/s.agcmst.for agcmst.for 420.20 8/4/07 18:30:53 ... (7 Replies)
Discussion started by: skumar11
7 Replies

10. Shell Programming and Scripting

Start time/end time and status of crontab job

Is there anyway to get the start time and end time / status of a crontab job which was just completed? Of course, we know the start time of the crontab job since we are scheduling. But I would like to know process start and time recorded somewhere or can be fetched from a command like 'ps'. ... (3 Replies)
Discussion started by: thambi
3 Replies
Login or Register to Ask a Question