Bash Monitoring Alert Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Monitoring Alert Script
# 8  
Old 06-22-2009
or
cat port_numbers.txt | sed 's/$/\n/g'
# 9  
Old 06-22-2009
Quote:
Originally Posted by research3
or
cat port_numbers.txt | sed 's/$/\n/g'
why exactly do you a cat there?
And btw:
Code:
$ echo '1 2 3 4' | sed 's/$/\n/g'
1 2 3 4n

# 10  
Old 06-22-2009
you can also try this:

HTML Code:
#!/bin/bash

#IFS='\n'

#set -x

port=80

for host in `cat host` 
do
	if  nc -zv -w1 $host $port 
	then
	echo "$host" up  
	else
	echo "$host" down	
	fi
done

cat host

test
Google
Yahoo!

---------- Post updated at 03:09 PM ---------- Previous update was at 03:07 PM ----------

sorry vgersh99 I mean:

HTML Code:
sed 's/ /\n/g'

Last edited by research3; 06-22-2009 at 08:22 PM..
# 11  
Old 06-23-2009
Thanks for everything. I finally got it working. Final solution is as follows:

Code:
#!/bin/sh
myHosts="host1.domain.com host2.domain.com host3.domain.com host4.domain.com"
myPorts=`cat /home/user/ping-script/port_numbers.txt`
for host in $myHosts
        do
                for port in $myPorts
                        do
                         if netcat -z $host $port
                         then
                                 echo port $host:$port is up
                         else
                                 date "+Server down - $host:$port -- %c"|mail -s "server down" test@domain.com
                          fi
                done
done

port_numbers.txt in it just has the port numbers all listed on a separate line.
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. What is on Your Mind?

Script to alert with email after a job got successful in monitoring tool

Hi guyz, Please send me a script which is to be sending an automatic email to particular mail id's when a job get complete with status successful. Please send me your script to my mail id : rehan.csjmu@gmail.com Thanks in Advance. ---------- Post updated at 11:33 AM ----------... (1 Reply)
Discussion started by: Rehan Ahmad
1 Replies

3. Shell Programming and Scripting

Alert for monitoring

Dear All, I am new to unix scripting, i need to develop a alert system which get trigger when my scripts don't find any *.log file to copy from one directory to other directory. In detail my scripts run every day and it create a dummy file and check all those *.log file 1 day old and copy them... (3 Replies)
Discussion started by: guddu_12
3 Replies

4. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

5. Infrastructure Monitoring

Alert / Monitoring / Historial Data Open Source

hi guys my boss asked me for a tool to monitor and alert my Linux boxes... and some Win boxes... but not only monitor for high CPU Usage, hign memory usage and so on....he also wants a tool for historical data I mean something like I want to know the CPU Usage and memory usage for the last... (1 Reply)
Discussion started by: karlochacon
1 Replies

6. Linux

Memory monitoring and sending alert mail to users in network using shell script

i m workiing on a shell script which may monitors network memory and send alert to user if it increase a threshold (1 Reply)
Discussion started by: navdeep5673
1 Replies

7. Shell Programming and Scripting

need script bash alert email

Hello I have a server it is running more than 5 people Scripts I want to send a warning to the administrator for the main server All is written in the ssh strain For example, when typing the following command "ls" " rm " and other email sends the administrator for the main server About it... (2 Replies)
Discussion started by: x-zer0
2 Replies

8. Shell Programming and Scripting

Help with Monitoring script

Hi Gurus, Currently I am learning UNIX through online forums and unix blogs. I have the below requirement. I need to write a script to monitor server processes. For example, there are 3 processes currently running on the server.(java, pmrepagent, pmserver). If any of the process goes down,... (2 Replies)
Discussion started by: svajhala
2 Replies

9. Infrastructure Monitoring

Monitoring and Alert System

hi, i serarch monitoring and alert system. when HDD and services are down. Send email and sms alert to me and help desk. but i don't find any program. Can you help me ? Thanks. (1 Reply)
Discussion started by: oulutas
1 Replies

10. Shell Programming and Scripting

Monitoring a file - Basic Bash Question

*This is not homework I am new to UNIX and want to try this Monitoring a file demo* *If this is the wrong forum please move it - im new to the forums* $1 = the file to be monitored $2 = the time for the file to sleep If the file gets changed (using -nt) it will send my username mail saying... (2 Replies)
Discussion started by: Nolan-
2 Replies
Login or Register to Ask a Question