Skip to content

Instantly share code, notes, and snippets.

View hoangdh's full-sized avatar
🏠
Working from home

Dao Huy Hoang hoangdh

🏠
Working from home
View GitHub Profile
@hoangdh
hoangdh / get-login-failed.sh
Last active December 7, 2018 16:21
Zimbra - Login failed account in 5 minutes.
#!/bin/bash
## Get login fail in 5m
send-notify(){
sudo cat /opt/zimbra/log/audit.log | egrep "${timest}.*(authentication failed|invalid password)" > /tmp/get-audit.tenten
# sed -i '1s/^/`date '+%Y-%m-%d %H:%M'`\n/' /tmp/data.tenten
cat /tmp/get-audit.tenten | while read -r l
do
@hoangdh
hoangdh / check-services.sh
Last active March 7, 2020 04:52
Auto detect services stop and restart it. - iRedMail (Postfix, Dovecot, Amavisd, MySQL) on CentOS/RHEL 6.x
#!/bin/bash
services="dovecot postfix amavisd clamd"
tmp=""
for ser in $services
do
stat=`service $ser status | grep -w 'running'`
echo $ser $USER >> /tmp/restart-service.log
if [ -z "$stat" ]
then
@hoangdh
hoangdh / check-port.sh
Last active March 7, 2020 15:27
Check port 25 opened.
#!/bin/bash
file='list.txt'
port='25'
while getopts "p:f:" arg;
do
case $arg in
p)
port=$OPTARG
@hoangdh
hoangdh / renew-SSLFree-Zimbra.sh
Last active March 7, 2020 04:52
Script Renew SSL Let's Encrypt for Zimbra Virtualhost.
#!/bin/bash
# Renew SSL for domain without deploy
server=$(dig +short a `hostname -f`)
domain=$(echo "$1" | tr '[:upper:]' '[:lower:]')
dom_mx=$(dig +short a mail.$domain)
if [ "$dom_mx" = "$server" ] && zmprov gd ${domain} > /dev/null 2>&1
then
sudo certbot renew --cert-name mail.$domain
zmprov md $domain zimbraSSLCertificate "" zimbraSSLPrivateKey ""
chmod 600 /opt/zimbra/conf/domaincerts/$domain.*
@hoangdh
hoangdh / Note-linh-tinh.md
Last active November 17, 2018 15:28
Sưu tầm những link tài liệu tổng quan, cơ bản.
@hoangdh
hoangdh / get-ip-per-interface.sh
Last active March 5, 2019 08:52
Get interface's name with IP Address.
#!/bin/bash
# ifs=`ifconfig -a | grep "flags=" | cut -d":" -f1 | sort -u`
for x in `ifconfig -a | grep "flags=" | cut -d":" -f1 | sort -u` # $ifs
do
IP=`ip -f inet -o addr show $x | cut -d\ -f 7 | cut -d/ -f 1`
if [ -z "$IP" ]
then
echo "${x}: Not connected."
@hoangdh
hoangdh / find-command.md
Last active January 7, 2021 16:14
Câu lệnh find - Tìm kiếm file và thư mục trong linux - Tips & Tricks FIND command

Ghi chép tùy chọn của find

  • Các tùy chọn hay dùng:
    • -name: Tìm kiếm theo tên file/folder
    • -type: Theo kiểu, f: Folder; d: Directory
    • -mtime N: Thời gian tạo/chỉnh sửa. N: là số ngày
    • -exec: Thực thi gì đó với các file tìm được
    • -perm: Tìm theo quyền truy cập (RWX)
    • -user: Tìm file thuộc sở hữu của user nào đó
  • -group: Tìm file sở hữu của group nào đó
@hoangdh
hoangdh / download-vtvgiaitri.sh
Created November 6, 2018 14:46
Tải film từ VTV Giải trí.
#!/bin/bash
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if [ -e $1 ]
then
lists=`cat $1`
for x in $lists
do
name=`echo $x | grep -Eo '?.*?\.mp4' | awk -F '/' {'print $NF'}`
ffmpeg -i "$x" -c copy $name
done
@hoangdh
hoangdh / ip-to-country.sh
Last active October 30, 2018 09:59
Trace IP SYN Flood to country
#!/bin/bash
####
#
# Count IP send SYN's flag
#
####
list=`netstat -npt | grep SYN_RECV | awk {'print $5'} | cut -d':' -f1`;
for x in $list;
@hoangdh
hoangdh / add-swap.sh
Created October 29, 2018 07:06
Auto add SWAP.
#!/bin/bash
### Get current swap size
info=`free -m | grep "Swap:"`
size_cur=$(echo $info | awk {'print $2'})
echo -e "Current swap size: $size_cur"
read -p "Enter new size (Unit: MB): " size_new