Help with time comparison shell script for HP-UX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with time comparison shell script for HP-UX
# 1  
Old 10-10-2005
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?? Smilie

Please help me ... as I have tried to search the forum for clues .... and I am really stuck now.. Smilie 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  
Old 10-10-2005
Why dont you look at crontab ? Using crontab, you can schedule your current script to run once a day at 1830.
# 3  
Old 10-10-2005
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 Smilie ....
# 4  
Old 10-10-2005
- 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  
Old 10-10-2005
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  
Old 10-11-2005
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  
Old 10-12-2005
MySQL 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. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date and Time comparison using shell script

Hi, I'm having two fields in the file F1|F2 20111220|102000 F1 ->YYYYMMDD F2 ->HHMMSS Now, I need to compare this with current date & time and need to return the difference value in hours. Already, I checked with datecalc from the forum. So, need hints from Shell Gurus. Thanks (10 Replies)
Discussion started by: buzzusa
10 Replies

2. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

3. Shell Programming and Scripting

Korn shell script comparison

I have a scenario to implement in Korn shell script. Here it is.. I need to compare two values to see whether they are same or not. The issue is that the values coming in for comparison can be a string or an integer which can be determined during run time only. Which korn shell comparison... (1 Reply)
Discussion started by: vani123
1 Replies

4. Shell Programming and Scripting

File comparison in shell script

Hi, I have written one script : #!/bin/bash echo -n -e "\nEnter how many files : " read no for (( j=1; j<=$no; j++ )) do echo -n -e "\nEnter $j File name : " read name done for (( j=1; j<=$no; j++ )) do FILE=`find ./ -type f -name "${name}"` echo "$FILE" (3 Replies)
Discussion started by: kiran_j
3 Replies

5. Solaris

String Comparison in Shell script

I Have a script which gets the status of oracle database and if the status is READ WRITE ..it should echo "db is up " else "db is down" Here is the code if then echo "db up" else echo "db down" fi done; The script is giving me out put "db down" even thoug the value of... (6 Replies)
Discussion started by: njafri
6 Replies

6. Shell Programming and Scripting

How to do row comparison in shell script

Hi, I need help on doing the below thing in shell script. I have a file with millions of rows called "abc.txt". i have another file with millions of rows called "xyz.txt". I would like to do the below operation. Open the abc.txt, read the first line, do some operations on the column... (2 Replies)
Discussion started by: informsrini
2 Replies

7. Shell Programming and Scripting

need help in writing a comparison shell script

I have a folder a1 with the following files sample_1.log sample_2.log sample_3.log sample_4.log sample_5.log sample_6.log In another folder there is a file b with the value 5 My script should take the value 5 ( file b), compare it with the files in folder a1, if file name contains... (1 Reply)
Discussion started by: Nagesh1
1 Replies

8. Shell Programming and Scripting

bash shell script string comparison

I want to remove a line that has empty string at second field when I use cut with delimeter , like below $cat demo hello, mum hello, #!/bin/sh while read line do if then # remove the current line command goes here fi done < "demo" i got an error message for above... (4 Replies)
Discussion started by: bonosungho
4 Replies

9. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

10. Shell Programming and Scripting

Time comparison

hi friends, I am new to shell scripting and i am using KSH shell .I would like to automate our daily routine manual tasks .first i ll explain the situation .I will list out the contents of directory named "log" using "ls " and verify whether all the listed files time differences is... (3 Replies)
Discussion started by: rdhaprakasam
3 Replies
Login or Register to Ask a Question