need help with little bash server monitor script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need help with little bash server monitor script
# 1  
Old 10-10-2011
need help with little bash server monitor script

hello,

i`m new in bash scripting and i getting an error with my little server monitoring script

example of my script:
Code:
#!/bin/sh
s1_ats=0


while [ 1 ]; do
sleep 5



s1=`ping -c 1 xxxx.xxxx.xxxx.xxxx | grep 64 | awk '{print $1}'`
if [ "$s1" == "64" ] ; then
  $s1_ats=0
  else
    if [ "$s1_ats" -ge "10" ] ; then
      echo -e "sms" >> /root/tikrinimas
      $s1_ats=0
      else
        let $s1_ats++
    fi
fi


done

i want to make, that 1 server pinging other servers and if ping fails x times it send`s to me an sms message. this
echo -e "sms" >> /root/tikrinimas is for this time, later i`ll connect an gsm device and that device will send an mesage if ping fails 10 times

but im getting errors and i dont know why.

thanks for any help or comments
# 2  
Old 10-10-2011
Hi grauzikas,

Welcome to the forum.
Can you please post the error messages?
# 3  
Old 10-10-2011
i alredy remaked that script, and now my else wont work

Code:
#!/bin/sh
s1_ats=0


while [ 1 ]; do
sleep 1



s1=`ping -c 1 1.2.3.4 | grep 64 | awk '{print $1}'`
if [ "$s1" == "64" ] ; then
  s1_ats=0
  else
    if [ "$s1_ats" < "3" ] ; then
      let s1_ats++
      echo $s1_ats
      else
        echo -e "sms" >> /root/tikrinimas
        s1_ats=0

    fi
fi


done

output:
Code:
sh -x monitoringas
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 0 ']'
+ let s1_ats++
+ echo 1
1
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 1 ']'
+ let s1_ats++
+ echo 2
2
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 2 ']'
+ let s1_ats++
+ echo 3
3
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 3 ']'
+ let s1_ats++
+ echo 4
4
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'
+ s1=
+ '[' '' == 64 ']'
+ '[' 4 ']'
+ let s1_ats++
+ echo 5
5
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 1.2.3.4
++ grep 64
++ awk '{print $1}'

in this example if else worked then after 3 ping fails it mus set s1_ats to 0 and write sms into /root/tikrinimas file, but how can i see that else wont work

if i getting replays then everithing works ok

Code:
 sh -x monitoringas
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ grep 64
++ awk '{print $1}'
++ ping -c 1 127.0.0.1
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1
++ ping -c 1 127.0.0.1
++ grep 64
++ awk '{print $1}'
+ s1=64
+ '[' 64 == 64 ']'
+ s1_ats=0
+ '[' 1 ']'
+ sleep 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Transfer files from one server with bash script

Hello to all, I want to copy from one server to another files of last 24 hours with size between 500MB and 2GB. The code below searches last files in 24 hours. find . -mtime -1 In order to copy faster I'd like to compress the files before copying them. How to automate the process of... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

3. Shell Programming and Scripting

Bash script monitor directory and subdirectories for new pdfs

I need bash script that monitor folders for new pdf files and create xml file for rss feed with newest files on the list. I have some script, but it reports errors. #!/bin/bash SYSDIR="/var/www/html/Intranet" HTTPLINK="http://TYPE.IP.ADDRESS.HERE/pdfs" FEEDTITLE="Najnoviji dokumenti na... (20 Replies)
Discussion started by: markus1981
20 Replies

4. UNIX for Dummies Questions & Answers

Running a C/C++ program and/or bash script from a server

I wish to be able to give to a client the opportunity to : 0) Turn one of my ubuntu computers into a webserver 1) See a webpage after visiting a url where an external user/client can set a couple of variables (e.g. Number1= ?, Number2=?) 2) By pressing "run" the program runs on my machine 3)... (1 Reply)
Discussion started by: frad
1 Replies

5. Shell Programming and Scripting

Bash script to test IP range on server

Hello, We have to configure servers with a range of IPs which is in itself a subject for another script assistance request -but- we have run into quite a few IP ranges with routing problems lately. I've been trying to figure out the best way to test a range of IPs, I mean, manually it's not... (4 Replies)
Discussion started by: boxgoboom
4 Replies

6. Shell Programming and Scripting

Korn/bash Script to monitor a file a check for specific data

Hi, Im trying to write this script but im stuck on it, basicaly what i want to do is to write a code to verify a log file ( apache log file for example ) and for each new line with specific data , then, output this new line for another file: full ex: output of the server.log is (... (4 Replies)
Discussion started by: Thales.Claro
4 Replies

7. Shell Programming and Scripting

Script to monitor JBoss web server

Hello All, I need a shell script to monitor JBOSS web server.If the JBOSS web server is down, then the script should send a mail. Please help on this. Regards, Sachin (2 Replies)
Discussion started by: nsachin
2 Replies

8. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

9. Shell Programming and Scripting

(w)get web server's directories + bash script

Hi everyone. I need to write a script which will download files/folders (a huge collection) to the local file server (centOS 4.4 Server), and check regularly (every 6 hours or so if any new files are present, or if the old ones were modified to update contents). Any insights on how to tackle... (2 Replies)
Discussion started by: reminiscent
2 Replies

10. Shell Programming and Scripting

server monitor script...

hi all i have a script which will write a log file depending upon output of TOP command ( i am on HP-UX ) and some rules to analyze processes if process falls under that rule then log entry in file. i am ready with this part i have perl script which does this for me but i have 3 HP servers and... (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question