- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Check for file multiple times
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
Discussions
Discussions
Forums
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
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
тАО07-17-2008 01:49 AM
тАО07-17-2008 01:49 AM
I have been away from UNIX for a very long time and am in need of some help.
I need to be able to check for the existance of a specific file name say 'file.dat' in a particular location
If the file exists then run a second process (at processname now)
If the file does not exist then sleep 5 minutes and look for it again for up to 3 times
Once the file has been found and processed once only then finish
Any hints tips or specific examples would be appreciated
Running HPUX by the way
This is what I have so far
The process searches up to 3 times for the arival of a file. Once it has detected the file and processed the job , it is important that it does not do so again. How can I prevent this?
2 In this version of the code the script does not loop back to try again when the file is not found
#!/bin/ksh
file="/path/to/file/file.dat"
for i in 1 2 3
do
if [[ -f $file ]] ; then echo " file found"
at -f jtest_get_file.sh now
else
echo "File not found!".
break
fi
sleep 3 # 3 seconds will be 600
done
Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 01:51 AM
тАО07-17-2008 01:51 AM
Re: Check for file multiple times
Suggest a while loop
while true
do
# your code
done
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 02:16 AM
тАО07-17-2008 02:16 AM
Re: Check for file multiple times
Well, you can remove the file. You can rename/move the file. Or you can change the permission on the file.
Or you can create another file that says you processed the file. Of course you need to clean up two files in order to start this process again.
Or you can just exit the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 02:17 AM
тАО07-17-2008 02:17 AM
Re: Check for file multiple times
many thanks for your help so far
I now have
while true
do
for i in 1 2 3
do
if [[ -f $file ]] ; then echo " file found"
at -f jtest_get_file.sh now
extracted='y'
echo $extracted
else
echo "File not found!".
break
fi
sleep 3 # 3 seconds will be 600
done
Unfortunatly it is now looping for ever
By the way I see from your profile who you work for. I helped to impliment an Oracle based ERP system in your Southampton office in the UK
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 02:23 AM
тАО07-17-2008 02:23 AM
Re: Check for file multiple times
Thank you for your help.
I am happy with both of your sugestions. I am fine with moving or re naming the file , but how would I exit the script after the secdond process has run once only?
What is the syntax and where would I position it?
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 04:19 AM
тАО07-17-2008 04:19 AM
Re: Check for file multiple times
Try this variation:
#!/usr/bin/sh
look=0
while true
do
if [[ -f "${file}" ]] ; then
echo "'$file' file found"
at -f jtest_get_file.sh now
extracted='y'
echo $extracted
exit 0
fi
echo "File not found!"
(( look=$look+1 ))
[ $look -ge 3 ] && exit 1
sleep 3
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 04:51 AM
тАО07-17-2008 04:51 AM
Re: Check for file multiple times
Thank you sir !
That works perfectly
Many thanks for you help
Regards
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 05:05 AM
тАО07-17-2008 05:05 AM
SolutionYou are welcome! ...please read too:
http://forums12.itrc.hp.com/service/forums/helptips.do?#28
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-17-2008 10:22 PM - edited тАО09-11-2011 06:29 AM
тАО07-17-2008 10:22 PM - edited тАО09-11-2011 06:29 AM
Re: Check for file multiple times
>I am happy with both of your suggestions. I am fine with moving or renaming the file, but how would I exit the script after the second process has run once only?
>What is the syntax and where would I position it?
You can use exit to get out of the script, return to get out of the function. Or you can use break to get out of the loop.
I assume this is where your "echo $extracted" is?
extracted='y'
echo $extracted
break 2
The "2" is needed to get out of both the "for" and "while" loops.
I'm not sure why you want that while there? I assumed Steven meant replace that "for" loop by a while loop? (It's hard to use "for" for lots of times.
#!/usr/bin/sh
file="???"
typeset -i count=3
extracted=
while (( (count -= 1) >= 0 )); do
if [ -f "${file}" ]; then
echo "'$file' file found"
at -f jtest_get_file.sh now
extracted='y'
echo $extracted
break
fi
echo "File not found!"
(( count == 0 )) && break; # skip last sleep
sleep $(( 5 * 60 )) # 5 minutes
done
# would need to test $extracted if desired