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 :
- http://www.quietearth.us/articles/2006/09/25/Ubuntu-Sending-command-line-mail
- http://theos.in/shell-scripting/send-mail-bash-script/
- http://ubuntuforums.org/showthread.php?t=772999
Butuh Hosting ? Hosting Surabaya Directadmin Hosting