Results 1 to 4 of 4
Hi all,
I have a unique problem. I am trying to add a command at the end of a current script.
The existing script basically produces a file and copies ...
- 04-27-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 2
Please help me with shell scripting...
Hi all,
I have a unique problem. I am trying to add a command at the end of a current script.
The existing script basically produces a file and copies it to a specified directory. The file then gets decoded by a different script and disappears. The whole process takes 30 seconds between the file's generation and it's subsequent dissappearance.
My problem: I need to write either a "while" statement or an "if,else" statement to preclude the script from ending until that file disappears from the directory that it was placed into.
Here is what I'm thinking: I need to cd to that directory, grep for the file (if that is possible) and if it exists, sleep 10[s] and check for it again. When that file does not exist, then the script can exit.
It sounds like it should easy, I just can't figure out how to do it. Here is what I have, which I know is very wrong.
while [ cd /home/frorule grep filename = 0 ]
sleep 10[s]
My feeble brain and I thank you for any input you can provide.
ps- this is not homework. I'm at work and I'm trying to improve this script so my fellow coworkers don't jump to the next step before the entire process is finished.
- 04-28-2007 #2
heh.
Well sounds like the right idea. I guess you just need the mechanics of the solution. For a while loop you need syntax like this:
As for greping the file. You'd only need to use 'grep' if you were unsure of what exactly the filename was. I'm assuming you know what the filename is, suppose it's called myfile.txt. To see if it exists you can use a true/false statement like this:Code:while TRUE-FALSE-STATEMENT; do STUFF... done
(the -e stands for "exists")Code:[ -e /path/to/myfile.txt ]
So putting it all together:
This will sleep every ten seconds until the file does not exist.Code:while [ -e /path/to/myfile.txt ]; do sleep 10 done
Hope that helps. If not, post back and I'll gladly help some more.
Avatar from xkcd.com, a hilarious computer related webcomic.
- 05-01-2007 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 2
jpal, you are a linux genius.
Thanks for your help!!
Jeff
- 05-02-2007 #4
Happy to help.
Avatar from xkcd.com, a hilarious computer related webcomic.


Reply With Quote