The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
epoch time in shell script robsonde SUN Solaris 14 05-12-2009 12:08 PM
Time out in shell script for a stament/line gvsreddy_539 Shell Programming and Scripting 5 10-02-2007 10:12 AM
Newbee Needs Help - Time comparison danedder Shell Programming and Scripting 4 05-25-2005 12:26 PM
C shell script for time matching Ringo Shell Programming and Scripting 1 08-07-2003 01:26 PM
File Time Comparison Question pc9456 UNIX for Advanced & Expert Users 2 07-23-2003 03:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2005
gummysweets gummysweets is offline
Registered User
  
 

Join Date: Jun 2005
Location: London
Posts: 7
Help with time comparison shell script for HP-UX

I am using Korne Shell in HP-Ux. Can someone give me and idea on how I can write a shellscript on how to do this please:-

On our HP-UX server, a batch file is run every evening at about 6:30pm. The first step of this batch file will touch an empty "flag" file to indicate that the batch has already started running. This flag is removed at the end of the evening batch file. So bascially, as long as this flag exists, the batch file is not allowed to be run by another operator. The problem is I need to built in some testing that if the batch file has already been run once within the 24 hours cycle, it mustn't be run again.

I thought about setting a timestamp into the "flag" file I create at the beginning of the batch run and call it "BatchRunning". Then rename this flag file and call it "batchRan" so it will be served as sort of time marker for comparison later. So if the batch file is re-run then a comparison can be made between the two files "BatchRunning" and "batchRan". If "BatchRunning" is less than "batchRan" by 24 hours then abort the batch file immedately and display a message to the operator.

So that's the theory, how do I script this in Korne Shell please??

Please help me ... as I have tried to search the forum for clues .... and I am really stuck now.. In my search, on time comparison, it picked up the "datecalc" script but I am not sure if it can be applied to my problem ( it looks far too complicated).

Many thanks in advance,
  #2 (permalink)  
Old 10-10-2005
vino's Avatar
vino vino is online now Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Why dont you look at crontab ? Using crontab, you can schedule your current script to run once a day at 1830.
  #3 (permalink)  
Old 10-10-2005
gummysweets gummysweets is offline
Registered User
  
 

Join Date: Jun 2005
Location: London
Posts: 7
No, can't use crontab at all because the batch file is not always run at 6:30pm. Sometimes, the end of days can finish late. On some of our servers, the evening batch file can only be run if another system has finished. This is why the batches can only be kicked off by our operators in a manual mode if you like.

Thanks for your suggestion anyway ....
  #4 (permalink)  
Old 10-10-2005
rein rein is offline
Registered User
  
 

Join Date: Dec 2004
Location: Zürich
Posts: 146
- You can use 'touch' to create the lock files.

- day=`date +%d` gives the day value of now

- minutes=`date +%m` gives the minute value of now

- ls -l /path/to/dir/file | awk '{print $7}' gives the date entry of the file

- file1 -nt file2
True, if file1 exists and is newer than file2.

- file1 -ot file2
True, if file1 exists and is older than file2.

With this information you should be able to write the script.
  #5 (permalink)  
Old 10-10-2005
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Just a little correction.
Quote:
Originally Posted by rein
- minutes=`date +%m` gives the minute value of now
Code:
date +%m
gives the month in digits
Code:
date +%M
gives the minute value of now.
  #6 (permalink)  
Old 10-11-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...
Code:
SECS=$(perl -e '@q=stat($ARGV[0]); print time-$q[9]' batchRan)
if [[ $SECS -lt 82800 ]]
then
    echo Less than 23 hours since last run
    exit
fi
  #7 (permalink)  
Old 10-12-2005
gummysweets gummysweets is offline
Registered User
  
 

Join Date: Jun 2005
Location: London
Posts: 7
Thumbs up Thank you

Just to say thank you all for looking at my initial query. Using some of the hints given here, I have come up with a script which does the job. Being a newbie to Unix Support, I have found this forum very supportive.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0