Need to run a script for exactly 3 hours.
It will have while loop which is to keep running until its 3 hours since the script's invocation time and then exit the script.
Script could be invoked at any time.
May have to change the number of hours later as per need.
Are there any existing date function in aix version3 that could help me add specific number of hours to the time when script is invoked and store it in variable? If not, can you suggest me some other approach please?
date -d option does not exist on my aix system.
value of $TZ is :
AIX 3 is about 20 years old by now! If the above solutions do not work in your ancient environment you can try a diffent approach: Start a script in the background that sleeps for the desired time and then creates a flag file that causes the main script to stop.
Script sleeperagent.ksh:
#!/bin/ksh
# usage: sleeperagent.ksh <flagfile> <timeinseconds>
[ ! -f $1 ] && sleep $2 # flagfile should not exist when we start sleeping
touch $1
Assuming you have permissions to use "cron", I'd start the script with an "at" job to create a flag file in 3 hours time. Then test for the presence of the file in the main "while" loop of the script. This has the added advantage that you can stop the script whenever you want. There may by subtle syntax differences for AIX.
echo "touch /tmp/exitflagfile" | at now +3 hours
while whatever
do
[ if -f /tmp/exitflagfile ]
then
rm /tmp/exitflagfile
exit
fi
# Rest of script
done