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 / http-code-status.sh
Last active February 7, 2019 03:39
Check HTTP code status using Nagios/check_mk plugin
#!/bin/bash
SERVER=$1
STATUS=$(curl -sL -o /dev/null -w "%{http_code}" $SERVER)
case $STATUS in
200)
echo "$SERVER is still running."
exit 0
;;
*)
echo "$SERVER is not running."
@hoangdh
hoangdh / gen-part.sh
Created February 2, 2019 15:07
Cutting video duration greater than 60 minutes using FFMPEG.
#!/bin/bash
dur=`ffprobe -v error -select_streams v:0 -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 "$1" | head -n 1`
## Chinh so phut o $parts, $t va 2 cau lenh cut
flag=`echo "$dur > 3600" | bc`
name=`echo $1 | tr '.' ' ' | awk {'print $1'}`
if [ $flag = "1" ]
then
@hoangdh
hoangdh / install-MariaDB10.3.C7.sh
Last active May 27, 2019 03:35
Quick install MariaDB 10.3 on CentOS 7.3
#!/bin/bash
cat > /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos73-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
@hoangdh
hoangdh / install-docker-c7.sh
Last active October 25, 2022 04:15
Install Docker + Docker Compose on CentOS 7
#!/bin/bash
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io -y
systemctl start docker
systemctl enable docker
curl -sLk "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
@hoangdh
hoangdh / update-timezone.sh
Created February 8, 2019 17:03
Automatic update time/date on Linux
#!/bin/bash
timedatectl set-timezone Asia/Ho_Chi_Minh
yum install ntp -y
ntpdate pool.ntp.org
@hoangdh
hoangdh / md5-hash.sh
Created February 11, 2019 04:47
How to get the MD5 hash of a string directly in the terminal
#!/bin/bash
encrypt(){
echo -n "$1" | md5sum | awk {'print $1'}
# echo -n "$1" | openssl md5 | awk {'print $2'}
}
RAW="$1"
encrypt $RAW
@hoangdh
hoangdh / install-youtube-dl.sh
Last active March 16, 2023 13:48
Install youtube-dl and FFMpeg on Linux
#!/bin/bash
wget -qP /tmp/ https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
cd /tmp
tar -xf /tmp/ffmpeg-release-amd64-static.tar.xz
cp -R /tmp/ffmpeg-*/ff* /usr/local/sbin/
rm -rf /tmp/ffmpeg-*
curl -sL https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
chmod a+rx /usr/local/bin/youtube-dl
@hoangdh
hoangdh / sync-password-hash-zimbra.sh
Last active January 31, 2024 14:55
Sync password hash from another system to Zimbra.
#!/bin/bash
FILE=$1
if [ -e $FILE ]
then
cat $FILE | while read -r l
do
text=`echo $l | sed "s/(//g; s/'//g; s/)//; s/;//g; s/)//g; s/,//g"`
USER=$(echo $text | awk '{print $1}')
@hoangdh
hoangdh / backup-to-aws.py
Last active February 26, 2019 15:56
Upload, delete files on AWS S3
import boto3
from datetime import datetime, timedelta
# Requeriment
## python2.7, boto3 (pip install boto3)
## ~/.aws/credentials - Contain your credentail (API, Secret)
## ~/.aws/config - Contain your config (Region,...)
## More details: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html
# Upload a file into Bucket
@hoangdh
hoangdh / backup-all-databases-mysql.sh
Last active February 22, 2021 04:01
Dump all database on MySQL/MariaDB systems.
#!/bin/bash
BACKUP_DIR="/opt/backup"
mkdir -p ${BACKUP_DIR}
## Get all databases on system
USER="root"
PASSWORD=""
DBS=`mysql -u ${USER} -p${PASSWORD} -sNe "SHOW DATABASES;" | grep -Ev "information_schema|performance_schema|mysql|test"`
for DB in ${DBS}