Tuesday, November 12, 2024
Bash Script Zimbra

Membuat Script grep log zimbra dan di kirim ke email

Mungkin anda pernah mengalami ingin membuat report untuk log zimbra dan di kirim ke email , pada case kali ini log tersebut di buat untuk meng grep pengiriman hanya ke domain tertentu.

Berikut contoh nya :

  • Buat file misal zimbra.sh
  • Jangan lupa untuk permission nya
nano /usr/local/sbin/zimbra.sh
chmod a+x /usr/local/sbin/zimbra.sh
  • kemudian isi kan script berikut ini :
#!/bin/bash
#
# created : 21 september 2020
# by      : xxx
#

# overwrite file
echo -e "Log per $(date +%Y-%m-%d)\n\n" > /tmp/tex.txt

# grep log pgbi.com
cat /var/log/zimbra.log | grep pgbi.com | grep "$(date +'%b %d')" >> /tmp/tex.txt

# send report by email
echo -e "[ $(date +'%d-%m-%Y') ]\n" | mailx -s "Log zimbra $(date +'%d %b %Y')"
-S smtp=smtp://smtp.xxx.net:25 -S from="server@xxx.net" -a /tmp/tex.txt -b "ro@xxx.com" postmaster@tex.com

Keterangan :

Baris Pertama untuk overwrite file yang ada di path /tmp/tex.txt
Baris kedua grep pengiriman menuju domain pgbi.com dan di simpan di file /tmp/tex.txt
Baris ke tiga adalah script untuk mengirim email menggunakan mailx yang sudah di install terlebih dahulu , pengiriman tersebut menggunakan smtp zimbra itu sendiri. di kirim ke bcc ro@xxx.com dan to nya ke postmaster@tex.com
  • Silahkan di test dahulu , jika sudah berhasil di test dan masuk ke email tujuan maka tinggal setting crontab nya seperti berikut :
crontab -e

30 23 * * * /usr/local/sbin/zimbra.sh
Keterangan : script akan di eksekusi tiap hari jam 23.30
(Visited 258 times, 1 visits today)
Baca Juga :  Mengatasi Server yang Waktu / Date nya salah diarenakan batre cemos habis

Similar Posts


Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270

Warning: Trying to access array offset on value of type bool in /home/des1gn/hendro-wibiksono.web.id/wp-content/plugins/floating-related-posts/floating-related-posts-pro.php on line 270