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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / change_md5_file_linux.md
Last active December 18, 2018 06:50
How to change MD5 of file using Linux command

How to change MD5 of file using Linux command

Either command should add 10 bytes to the end of your file. This should mean the MD5 (when next calculated) should be different.

truncate -s +10 <filename>.ext
dd if=/dev/zero bs=1 count=10 &gt;&gt; .
@hoangdh
hoangdh / get-asn.sh
Last active January 8, 2019 09:34
Free IP address to ASN database - API iptoasn.com
#!/bin/bash
IP2=$1
IP=${IP2:-$(echo $(($RANDOM % 256)) $(($RANDOM % 256)) $(($RANDOM % 256)) $(($RANDOM % 256)) | sed 's/ /./g')}
if [[ "$IP" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then
echo -n "$IP: "
curl https://api.iptoasn.com/v1/as/ip/${IP} -s | grep -Eo '\"as_number\"(.+?)([0-9]),' | grep -Eo '[0-9]+'
# curl https://api.iptoasn.com/v1/as/ip/${IP} -s | sed 's/,/ /g;s/\"//g' | grep -Eo 'as_number.*' | awk {'print $1'} | cut -d':' -f2
else
#!/bin/bash
check_port() {
sort $1 | uniq -c | sort -nr | awk {'print $2'} | while read -r ip;
do
if ping -c 1 -w 1 $ip > /dev/null 2>&1;
then
if nc -vz -w 3 $ip 25 > /dev/null 2>&1;
then
echo $ip - Port 25 Opened;