Bash Script Monitoring sederhana dengan mail Alert

Mungkin suatu ketika anda membutuhkan script untuk memonitor status hardware/PC dalam keadaan terkonesi atau putus. berikut simple script hasil ramuan mbah Google….

Tested On UBUNTU.

untuk mengirim alert email anda membutuhkan mail Transport, install mail utils

# apt-get install mailutils

coba reconfigure Exim

# dpkg-reconfigure exim4-config

default Exim membuka port 25  jika anda tidak menginginkan tutup saja

# /etc/init.d/exim4 stop
# update-rc.d -f exim4 remove

done, selanjutnya

Contoh Ping check dengan Bash Script

#!/bin/bash
ping -c 1 64.233.161.99
if [ $? -eq 1 ]
then
    zenity --info --text "Failed to reach google, panic!"
fi

done,

Contoh bash Script untuk kirim email

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SET-EMAIL-SUBJECT"
# Email To ?
EMAIL="admin@somewhere.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

Ramuan Akhir

#!/bin/bash
ping -c 1 $1
if [ $? -eq 1 ]
then
  # script to send simple email
  # email subject
  SUBJECT="DOWNTIME ALERT"
  # Email To ?
  EMAIL="admin@domain.com"
  #  Email text/message
  EMAILMESSAGE="/tmp/emailmessage.txt"
  echo "DOWNTIME ALERT"> $EMAILMESSAGE
  echo "Just want to inform that connection from $1 currently DOWN" >$EMAILMESSAGE
  echo "powered by arek-BSD" >>$EMAILMESSAGE
  # send an email using /bin/mail
  mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

simpan dengan nama ping.sh dan chmod 755

testing

# ./ping.sh detikinet.com
PING detikinet.com (203.190.241.43) 56(84) bytes of data.
64 bytes from 203.190.241.43: icmp_seq=1 ttl=54 time=29.1 ms

— detikinet.com ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 29.165/29.165/29.165/0.000 ms

dan Jalankan sebagai Cron jadwal sesuai dengan keinginan anda

Sumber :

Butuh Hosting ? Hosting Surabaya Directadmin Hosting

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

  1. LinkEx PHP Link Exchange Management Sederhana tapi Mantab

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Turn on pictures to see the captcha *

What is 10 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

Switch to our mobile site