Skip to content

Instantly share code, notes, and snippets.

Avatar
🏴
revolution

Rojen Zaman rojenzaman

🏴
revolution
View GitHub Profile
@rojenzaman
rojenzaman / ban.sh
Created Mar 3, 2020
fail2ban'da 5 defadan fazla banlanan ip adresi olursa onu /etc/hosts.deny dosyasına ekleyecek bir script
View ban.sh
#!/bin/bash
#Written by @keraattin
CURRENT_DATE=$(date +"%Y-%m-%d")
CREATE_TODAY_FILE=$(touch /tmp/today_banned.txt)
TODAY_BANNED=$(cat /var/log/fail2ban.log | grep $CURRENT_DATE | grep Ban | gawk '{print $8}' >> /tmp/today_banned.txt)
COUNT=$(sort /tmp/today_banned.txt | uniq -c)
@rojenzaman
rojenzaman / url-shortener.sh
Last active May 21, 2020
URL Shortener For Static Web Pages (written by bash shell programming language)
View url-shortener.sh
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "./`basename $0` <write url here> <write your site directory here> [second] [\"title\"] [\"html code or txt\"]";
exit 1;
fi
url=$1
directory=$2
if [ "$#" -gt 1 ]; then
@rojenzaman
rojenzaman / pdf2title
Created May 25, 2020
Simple manage PDF title and author name by exif data.
View pdf2title
#!/bin/bash
#
# Change the PDF title.
function guide() {
echo -e "usage: `basename $0` \"PDF Title\" \"Author Name\" pdfFileName.pdf";
exit 1;
}
@rojenzaman
rojenzaman / image-compress.sh
Created May 25, 2020
code to compress your hugo website images
View image-compress.sh
#!/bin/bash
#add code to hugo project dir.
find static/images/uploads/ \( -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' \) -print0 | xargs -0 -P8 -n2 mogrify -strip -thumbnail '1000>' -format jpg
@rojenzaman
rojenzaman / parse_getopts.sh
Created Jun 13, 2020
parse command line arguments with getopts
View parse_getopts.sh
#!/bin/bash
function one() {
echo "one > $1"
}
function two() {
echo "two > $1"
}
@rojenzaman
rojenzaman / update_cdn_ip.sh
Created Jul 9, 2020
UFW Rules Update for Cloudflare CDN
View update_cdn_ip.sh
#!/bin/bash
cd /root/cf
curl https://www.cloudflare.com/ips-v4 > ips-v4
curl https://www.cloudflare.com/ips-v6 > ips-v6
for i in `<ips-v4`; do ufw allow from $i proto tcp to any port 80,443; done
for i in `<ips-v6`; do ufw allow from $i proto tcp to any port 80,443; done
@rojenzaman
rojenzaman / wdb-create.sh
Created Jul 9, 2020
Wordpress Database Creator
View wdb-create.sh
#!/bin/bash
if [ "$#" -lt 4 ]; then
echo "`basename $0` <db name> <db user> <ip> <db password> [sql]";
exit 1;
fi
mysql <<EOF
CREATE DATABASE $1;
CREATE USER $2@localhost IDENTIFIED BY '$4';
GRANT ALL PRIVILEGES ON $1.* TO $2@localhost identified by '$4';
CREATE USER $2@$3 IDENTIFIED BY '$4';
@rojenzaman
rojenzaman / install-wp.sh
Created Jul 9, 2020
Install WordPress from command line.
View install-wp.sh
#!/bin/bash -ex
if [ "$#" -lt 2 ]; then
echo "`basename $0` <site> <wp.zip>";
exit 1;
fi
SITE=$1
WPZIP=$PWD/$2
cd /var/www/$SITE/public_html
@rojenzaman
rojenzaman / gen_pass.sh
Last active Jul 9, 2020
Password Generator Bash (Very Simple)
View gen_pass.sh
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "`basename $0` <8-92>";
exit 1;
fi
PASS=`date +%s | sha256sum | base64 | head -c $1`
echo "$PASS";
View get_ip_info.sh
#!/bin/bash
function increment_error_code {
error_code=$((error_code + 1))
}
function echo_error {
(>&2 echo -e "${RED}${1}${NC}")
}