- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Help regarding while loop.
Operating System - Linux
1755676
Members
3054
Online
108837
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО03-17-2008 02:30 AM
тАО03-17-2008 02:30 AM
Hello All,
Looking for a pointer for the following.
Script should Wait for a response file ( some text file) for 100mins, if the file comes with in 100min, script should continue.
If the file doesn't arrive after 100min, it needs to abort the script.
Can you please through some pointer on this.
Regards,
Raghu.
Looking for a pointer for the following.
Script should Wait for a response file ( some text file) for 100mins, if the file comes with in 100min, script should continue.
If the file doesn't arrive after 100min, it needs to abort the script.
Can you please through some pointer on this.
Regards,
Raghu.
Solved! Go to Solution.
- Tags:
- while loop
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2008 02:43 AM
тАО03-17-2008 02:43 AM
Re: Help regarding while loop.
I'm going to assume you're writing a shell script rather than (for example) a C program.
while :
do
if
[ -f $your_file ]
then
do next bit of script
else
let counter=counter+1
if
[ $counter == 10 ]
then
break
else
sleep 600
fi
fi
This tests for the existence of the file every 10 minutes. If the counter reaches 10, 100 minutes have elapsed and the script breaks if the file does not exists. If you want to check more often, reduce 600 and increase counter.
I haven't tested this - it's "back of an envelope" stuff - so it may need a tweak or two, but I think it will set you on the way.
Mark Syder (like the drink but spelt different)
while :
do
if
[ -f $your_file ]
then
do next bit of script
else
let counter=counter+1
if
[ $counter == 10 ]
then
break
else
sleep 600
fi
fi
This tests for the existence of the file every 10 minutes. If the counter reaches 10, 100 minutes have elapsed and the script breaks if the file does not exists. If you want to check more often, reduce 600 and increase counter.
I haven't tested this - it's "back of an envelope" stuff - so it may need a tweak or two, but I think it will set you on the way.
Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2008 04:06 AM
тАО03-17-2008 04:06 AM
Solution
Hi Raghu:
Here's another shell variation. Change the values of MAXSECS, STEP and FILE to meet your needs.
# cat ./watch
#!/usr/bin/sh
typeset -i MAXSECS=15
typeset -i STEP=3
typeset FILE=/tmp/mything
while true
do
if [ -f "${FILE}" ]; then
echo "'${FILE}' is now available"
break
fi
MAXSECS=${MAXSECS}-${STEP};
if (( ${MAXSECS} < 0 )); then
echo "No file seen"
exit 1
fi
sleep ${STEP}
done
exit 0
Regards!
...JRF...
Here's another shell variation. Change the values of MAXSECS, STEP and FILE to meet your needs.
# cat ./watch
#!/usr/bin/sh
typeset -i MAXSECS=15
typeset -i STEP=3
typeset FILE=/tmp/mything
while true
do
if [ -f "${FILE}" ]; then
echo "'${FILE}' is now available"
break
fi
MAXSECS=${MAXSECS}-${STEP};
if (( ${MAXSECS} < 0 )); then
echo "No file seen"
exit 1
fi
sleep ${STEP}
done
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-17-2008 06:01 AM
тАО03-17-2008 06:01 AM
Re: Help regarding while loop.
Hi JRF,
Awesome script. Great help indeed.
Regards.
Raghu
Awesome script. Great help indeed.
Regards.
Raghu
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP