Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Looking For a Script That Can Do The Following
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Looking For a Script That Can Do The Following

painfreepcpainfreepc Member
edited February 2014 in Help

Looking For a Script That Can Ping IP and Do The Following:

At script start-up it's only looking for a ping failure

step 1 - if success, Don't copy anything

step 2 ping failure, copy file A to folder

(failure 4 times before it copies file A to folder, if success before the 4th failure, go back to step 1)

After ping failure script is only looking for a ping success

step 3 - if failure, Don't copy anything

step 4 ping success, copy file B to folder

(success 4 times before it copies file B to folder, if failure before the 4th success, go back to step 3)

After ping success the script needs to go back to step 1 and look for ping failure,

I don't need the script to keep doing step 4 over and over because the server is now responding.

script for ubuntu 12.04/13.04


the script posted below by: SegmentationFault
i can use it with a very dirty work around,
but i am looking for a clean way to do it with just one script.

Comments

  • netomxnetomx Moderator, Veteran

    Well, in linux is easy, and windows, but it will be 2 scripts, not just 1

  • mikhomikho Member, Host Rep

    Use monit, it will ping and when a specific rule is met. Do a task.

  • painfreepcpainfreepc Member
    edited February 2014

    deleted

  • netomxnetomx Moderator, Veteran

    I meant 1 for windows, 1 for Linux.

  • Why do you need 2 scripts? A quick example for linux:

    #!/bin/bash
    ip=222.222.222.222
    test=$(ping -c 1 $ip > /dev/null; echo $?)
    case "$test" in
    0)  #success
        cp /folder/b /folder/a
        ;;
    *)  #failure
        cp /folder/c /folder/a
        ;;
    esac
    
    Thanked by 1painfreepc
  • painfreepcpainfreepc Member
    edited February 2014

    >

    Thank you,

    i can use it with a very dirty work around, i need something cleaner,

    see description at top.

  • painfreepcpainfreepc Member
    edited February 2014

    @SegmentationFault

    it will work with a few modifications, i can do what i need using your script

    to exec a "sed" command

    #!/bin/bash
    ip=222.222.222.222
    test=$(ping -c 1 $ip > /dev/null; echo $?)
    case "$test" in
    0)  #success
        cd /path/to/file/folder/  && 
        find ./ -maxdepth 1 -type f -exec sed -i 's/search_for_string_A/replace_with_string_B/' {} \;
        ;;
    *)  #failure
        cd /path/to/file/folder/  && 
        find ./ -maxdepth 1 -type f -exec sed -i 's/search_for_string_B/replace_with_string_A/' {} \;
        ;;
    esac
    

    thank you!

  • I have a simple ping monitor script that does a task when a service is down, and does another when the service comes back up. Perhaps you can modify it to your needs.


    https://github.com/blackdotsh/ping-monitor

Sign In or Register to comment.