Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Newbie jpalfree's Avatar
    Join Date
    Jul 2005
    Location
    Montreal, CA
    Posts
    198
    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:
    Code:
    while TRUE-FALSE-STATEMENT; do
    STUFF...
    done
    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:
    [ -e /path/to/myfile.txt ]
    (the -e stands for "exists")

    So putting it all together:
    Code:
    while [ -e /path/to/myfile.txt ]; do
    sleep 10
    done
    This will sleep every ten seconds until the file does not exist.

    Hope that helps. If not, post back and I'll gladly help some more.
    Avatar from xkcd.com, a hilarious computer related webcomic.

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    2

    Thumbs up

    jpal, you are a linux genius.

    Thanks for your help!!
    Jeff

  4. #4
    Linux Newbie jpalfree's Avatar
    Join Date
    Jul 2005
    Location
    Montreal, CA
    Posts
    198
    Happy to help.
    Avatar from xkcd.com, a hilarious computer related webcomic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...