Thread: loop script

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Philippines
    Posts
    14
    Rep Power
    0

    Question loop script


    Hi,

    I have to create a shell script that will loop every 5minutes and will check if file.txt exists. If file.txt exists, it will call another shell script to execute. Kindly help me, what looping technique should i use.

    Thanx.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    14
    Using pseudocode:

    Code:
        while TRUE
        do
              check file status & do something if condition meet
              sleep 360 seconds
        done
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Philippines
    Posts
    14
    Rep Power
    0
    does this also apply in unix shell script?

    Thanks
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    121
    Rep Power
    14
    The potential trouble with fpmurphy's technique is that "something" might not consume the file. So we stay in the loop, sleep again, and do "something" again. This may be what is needed. Or we might want to do "something" just once:
    Code:
    while FILE DOES NOT EXIST
    do
            sleep 300
    done
    run second script
    exit
    And again this is psuedo-code to simply illustrate the looping technique. It applies to all languages incuding most shells. Specific syntax is not possible since there are many languages including several shells.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Location
    Philippines
    Posts
    14
    Rep Power
    0
    Thanx so much
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    The potential trouble with perderabo's technique is that
    it will run once (if the second does not (re)call the first script)
    is this the Q ?

IMN logo majestic logo threadwatch logo seochat tools logo