LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2014, 05:35 AM   #1
Jykke
Member
 
Registered: Sep 2005
Posts: 201

Rep: Reputation: 19
monitoring the time in a process with shell


I have a shell script that is doing stuff, submitting other processes mainly.
Now I have a timer withing a while loop that monitors if the stuff has been running too long it will exit.

The problem is that I am running the program overnight and I now had a problem due to change of month.

I post few snippets from the script:
Code:
#!/bin/sh

gettime () {

years=`date +"%y"`
months=`date +"%m"`
days=`date +"%d"`
hours=`date +"%H"`
mins=`date +"%M"`
secs=`date +"%S"`
gettime=`echo $years*31104000+$months*2592000+$days*86400+$hours*3600+$mins*60+$secs | bc`

echo $gettime

}

starttime=`gettime`

submit_run_process.sh

actualtime=`gettime`
time_diff=`echo $actualtime - $starttime | bc`

echo "Runtime: " $time_diff
  if [ $time_diff -lt 7200 ] ; then
     echo "Runtime less than 2 hours from submit, suspicious - exit"
     exit
  fi
The problem is that my script assumes that month is 30 days and the multiplicator in seconds is 30*24*3600=2592000, now in May we had 31 days so the script had suddenly negative runtimes between May 31 and June 1 around midnight (which is then less than required 7200 seconds), ok I could take a multiplicator 31*24*3600 which would pass the if sentence, but in months with less than 31 days I would always have more than the required 2 hrs even if it was not so.

I am not keen on putting the whole calender into my subroutine and I do not want to bind another language into this, I would rather stick to shell, but at the moment I am a bit short of ideas. Any ideas? I recall there was some command that counts seconds from start? use uptime or so instead of date?
 
Old 06-02-2014, 05:40 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

perhaps I'm missing something here, but is there some reason you can't use
Code:
date +%s
?

Evo2.
 
Old 06-02-2014, 06:02 AM   #3
Jykke
Member
 
Registered: Sep 2005
Posts: 201

Original Poster
Rep: Reputation: 19
No, that was the one I missed myself Thx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to save the pid of a process at the time of process startup jhonnappier2007 Linux - Newbie 13 11-20-2011 11:54 PM
Shell script for reading a particular process contineously from process table vinaykori Linux - General 2 05-29-2009 06:52 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
Process Monitoring arb Linux - Newbie 1 09-15-2003 08:35 AM
Process monitoring arb Linux - General 3 09-15-2003 03:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration