Sponsored Content
Top Forums Shell Programming and Scripting need help with little bash server monitor script Post 302563199 by grauzikas on Monday 10th of October 2011 10:38:58 AM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
ATF-SH(1)						    BSD General Commands Manual 						 ATF-SH(1)

NAME
atf-sh [-s shell] -- interpreter for shell-based test programs SYNOPSIS
atf-sh script DESCRIPTION
atf-sh is an interpreter that runs the test program given in script after loading the atf-sh(3) library. atf-sh is not a real interpreter though: it is just a wrapper around the system-wide shell defined by ATF_SHELL. atf-sh executes the inter- preter, loads the atf-sh(3) library and then runs the script. You must consider atf-sh to be a POSIX shell by default and thus should not use any non-standard extensions. The following options are available: -s shell Specifies the shell to use instead of the value provided by ATF_SHELL. ENVIRONMENT
ATF_LIBEXECDIR Overrides the builtin directory where atf-sh is located. Should not be overridden other than for testing purposes. ATF_PKGDATADIR Overrides the builtin directory where libatf-sh.subr is located. Should not be overridden other than for testing purposes. ATF_SHELL Path to the system shell to be used in the generated scripts. Scripts must not rely on this variable being set to select a specific interpreter. EXAMPLES
Scripts using atf-sh(3) should start with: #! /usr/bin/env atf-sh Alternatively, if you want to explicitly choose a shell interpreter, you cannot rely on env(1) to find atf-sh. Instead, you have to hardcode the path to atf-sh in the script and then use the -s option afterwards as a single parameter: #! /path/to/bin/atf-sh -s/bin/bash ENVIRONMENT
ATF_SHELL Path to the system shell to be used in the generated scripts. SEE ALSO
atf-sh(3) BSD
September 27, 2014 BSD
All times are GMT -4. The time now is 07:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy