- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:15 AM
09-19-2002 08:15 AM
What I have to do is,
write a shell-script that keeps on checking whether the file test.txt exists, and once it does exist then load that in the database.
I have accomplished that by doing,
while ! test -s data.txt
do
sleep 120
done
if test -s data.txt
then
#load the data in database
fi
However, I also have to put in a condition in the while loop saying keep on checking for test.txt for three hours, but if it's not there in 3 hours then stop checking for that file and get out of the loop.
Can someone please provide some feedback on how to accomplish this? Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:17 AM
09-19-2002 08:17 AM
Re: Shell script
Please read data.txt wherever I have said test.txt. The file I have to wait for is data.txt
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:29 AM
09-19-2002 08:29 AM
Solutionscript1:
while ! test -s data.txt
do
sleep 120
done
if test -s data.txt
then
#load the data in database
mv data.txt loaddone.txt
fi
script2:
sh script1 &
myjob=$!
sleep 10800
if test -e loaddone.txt
then
kill -15 $myjob
else
rm loaddone.txt
fi
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:35 AM
09-19-2002 08:35 AM
Re: Shell script
# l = max number of loops
# s = sleep seconds
typeset -i i=0 l=0 s=120
let l=3*3600/$s
while [ $i -lt $l -a ! -s data.txt ]
do
sleep $s
done
if [ -s data.txt ]
then
# load
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:37 AM
09-19-2002 08:37 AM
Re: Shell script
let HOURS=3 #hours to run
let SLEEP=120 # seconds to check
let LOOPS="(HOURS*3600)/SLEEP"
while (( LOOPS ));
do
let LOOPS=LOOPS-1
if [[ -s data.txt ]];
then
fi
sleep ${SLEEP}
done
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:39 AM
09-19-2002 08:39 AM
Re: Shell script
for TEST in /test.data
do
your arguments come here
if [ $TEST = 1 ]
then
exit
fi
done
Regards,
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:39 AM
09-19-2002 08:39 AM
Re: Shell script
put sleep 10800 after the step
your arguments come here
Regards,
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 08:49 AM
09-19-2002 08:49 AM
Re: Shell script
another way:
sleep 10800 & # start sleeper
while kill -0 %1 >/dev/null 2>&1
do
[ -s data.txt ] && break
sleep 120
done
kill -HUP %1 # stop sleeper
if [ -s data.txt ]
then
# load
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 09:49 AM
09-19-2002 09:49 AM
Re: Shell script
It probably won't happen often but depending on the size of data.txt, your script could try to load the database while the file is still being written.
You may want to add a check using fuser or lsof to verify the file isn't being accessed before you do your load.
An fuser example:
inuse=`fuser $file 2>&1 | awk '{print $2}'`
if [ -z "${inuse}" ]
then
echo File ${file} not in use
# load the database
fi
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 09:55 AM
09-19-2002 09:55 AM
Re: Shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2002 01:45 PM
09-19-2002 01:45 PM
Re: Shell script
Again thank you for your feedback. To me Jordan's first answer was the most straightforward. The logic was easy to follow, so I have decided to use that...but everyone's got their points :-) !