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
SYSLOGOUT(8)						      System Manager's Manual						      SYSLOGOUT(8)

NAME
syslogout - modular centralized shell logout mechanism DESCRIPTION
syslogout is a generic approach to enable centralized shell logout actions for all users of a given system in a modular and centralized way mostly aimed at avoiding work for lazy sysadmins. It has only been tested to work with the bash shell. It basically consists of the small /etc/syslogout shell script which invokes other small shell scripts having a .bash suffix which are con- tained in the /etc/syslogout.d/ directory. The system administrator can drop in any script he wants without any naming convention other than that the scripts need to have a .bash suffix to enable automagic sourcing by the /etc/syslogout script. For shell sessions, the contents of /etc/syslogout.d/" will be sourced by every user at logout if the following lines are present in his $HOME/.bash_logout: if [ -f /etc/syslogout ]; then . /etc/syslogout fi If used for X sessions it is advisable to include the former statement into the Xreset script of the X display manager instead to prevent that closing of an terminal emulator window yields unexpected results in your running X session if your X11 terminal emulator is using a login shell. Be sure then to run it under the user-id of the X session's user. See the example files in /usr/share/doc/syslogout/ for illustration. Users not wanting /etc/syslogout to be sourced for their environment can easily disable it's automatic mechanism. It can be disabled by simply creating an empty file called $HOME/.nosyslogout in the user's home directory using e.g. the touch(1) command. Any single configuration file in /etc/syslogout.d/ can simply be overridden by any user by creating a private $HOME/.syslogout.d/ directory which may contain a user's own version of any configuration file to be sourced instead of the system default. It's names have just to match exactly the system's default /etc/syslogout.d/ configuration files. Empty versions of these files contained in the $HOME/.syslo- gout.d/ directory automatically disable sourcing of the system wide version. Naturally, users can add and include their own private scripts to be automagically executed by /etc/syslogout at logout time. OPTIONS
There are no options other than those dictated by shell conventions. Anything is defined within the configuration scripts themselves. SEE ALSO
The README files and configuration examples contained in /usr/share/doc/syslogout/ and the manual page for bash(1), xdm(1x), xdm.options(5), and wdm(1x). Recommended further reading is everything related with shell programming. If you need a similar mechanism for executing code at login time check out the related package sysprofile(8) which is a very close compan- ion to syslogout. BUGS
syslogout in its current form is mainly restricted to bash(1) syntax. In fact it is actually a rather embarrassing quick and dirty hack than anything else - but it works. It serves the practical need to enable a centralized bash configuration until something better becomes available. Your constructive criticism in making this into something better" is very welcome. Before i forget to mention it: we take patches... ;-) AUTHOR
syslogout was developed by Paul Seelig <pseelig@debian.org> specifically for the Debian GNU/Linux system. Feel free to port it to and use it anywhere else under the conditions of either the GNU public license or the BSD license or both. Better yet, please help to make it into something more worthwhile than it currently is. SYSLOGOUT(8)
All times are GMT -4. The time now is 03:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy