Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

seti@home bash scrip question

  • 26-02-2002 08:47PM
    #1
    Closed Accounts Posts: 1,026 ✭✭✭


    i'm writing a bash script to let me download 3 seti@home work units at a time.

    In the script that uploads the results I want to be able to run setiathome and check if it prints the line

    Can't connect to server; will retry in an hour.

    and if it does: restart the program after a minute.

    i think a mixture of grep and if statements might do it but i cant work it out.

    any help appreciated


Comments

  • Closed Accounts Posts: 296 ✭✭moist


    How about...?
    #!/bin/sh
    
    
    OUTPUT=`/path/to/prog 2>&1`
    
    CONTINUE="YES"
    
    while [ "${CONTINUE}" = "YES" ] 
    do
            if [  "${OUTPUT}" = "Can't connect to server; will retry in an hour." ]
            then    
                    echo "Can't connect, sleeping...."
                    sleep 60
                    OUTPUT=`/path/to/prog 2>&1 `
            else    
                    echo "Connected, exiting..."
                    CONTINUE="NO"
            fi      
    done
    


    Depending on weather your program prints that error message on stderr or not
    you may or may not have to use the " 2>&1 " bit (that just redirects stderr to stdout)
    Its probably no harm to just leave it.

    The test looks to see if the strings match _exactly_ so if your program
    prints other messages, obviously the test will always fail.

    In that case you could replace it with...
    OUTPUT=`/path/to/prog 2>&1 | grep "Can't connect to server; will retry in an hour."`
    


Advertisement