0

I have a bash script that takes a list of IP Addresses, and pings them every 15 seconds to test connectivity. Some of these IP Addresses are servers and computers as to which I have the ability to control. I would like to be able to do something of the following:

  • Run The Bash File
  • It pings non-controlled IP Addresses
  • It will list the controlled Computers
  • When a computer turns off, it sends my script a response saying it turned off
  • The script outputs accordingly

I have the code all set up that pings these computers every 15 seconds and displays. What I wish to achieve is to NOT ping my controlled computers. They will send a command to the bash script. I know this can be done by writing a file and reading such file, but I would like a way that changes the display AS IT HAPPENS. Would mkfifo be an viable option?

3
  • For Example. IP 1.1.1.1 shuts down, it sends my computer the command necessary, and the script updates then and there. Regardless of the 15 seconds countdown. Commented Jan 27, 2014 at 18:24
  • Why can't the script react to the command and remove the IP from whatever list it was using ? Commented Jan 27, 2014 at 18:27
  • The list is never shortened. It just prints online, and offline. When a computer goes offline, I would like it to update immediately. Commented Jan 27, 2014 at 18:29

1 Answer 1

1

Yes, mkfifo is ok for this task. For instance, this:

mkfifo ./commandlist

while read f < ./commandlist; do
    # Actions here
    echo $f
done

will wait until a new line can be read from FIFO commandlist, read it into $f and execute the body.

From the outside, write to the FIFO with:

echo 42 > ./commandlist

But, why not let the remote server call this script, perhaps via SSH or even CGI? You can setup a /notify-disconnect CGI script with no parameters and get the IP address of the peer from the REMOTE_ADDR environment variable.

Sign up to request clarification or add additional context in comments.

1 Comment

My computer has 2 monitors. My main usage monitor, and my statistics monitor. On the statistics monitor, I have online/offline IP Addresses refreshing every 15 seconds. With this set up, I do not see how the remote server could use CGI. SSH would allow the opportunity for writing to the mkfifo file, however, I would have to add some logic into the statistics script to allow for the setup you have provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.