Find the answer to your Linux question:
Results 1 to 3 of 3
hi i want to know how to create an IF. I currently have serveral servers mounted using samba. I have a backup script atm which works well. However when a ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    1

    Shell Script

    hi i want to know how to create an IF. I currently have serveral servers mounted using samba. I have a backup script atm which works well. However when a server goes off for whatever reason my backup deletes the files first and then goes to fetch the new data. When the server isnt present it doesnt copy any data so i loose a backup. Is there a way of using a IF in a shell script to detect a missing server e.g if ping timeout then dont delete

    thanks

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    The following if statement preforms a ping on IP address 192.168.0.1 and then checks for the string "0 received" in the response.

    Code:
    if [[ `ping -c1 192.168.0.1 | grep "0 received"` != "" ]] 
    then 
        echo "no ping" 
    fi
    Linux User #453176

  3. #3
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    Or:

    Code:
    ping -c1 -w1 192.168.0.1 >&- 2>&- ||echo "unreachable"

Posting Permissions

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