├── File Reader ├── file.txt └── File Reader.sh ├── Line-counter.sh ├── Decimal-to-hex.sh ├── Uptime.sh ├── List-dir.sh ├── Check_Directory_Size.sh ├── File Deleter.sh ├── Directory_Change.sh ├── Nmap-find-hostname.sh ├── Sleep_Examples.sh ├── Present Working Directory.sh ├── String Slicer.sh ├── Conversation Starter.sh ├── Random-emoji.sh ├── Convert_Videos_Directory_to_MP4.sh ├── File Generator.sh ├── Clear-cache.sh ├── Scan_Open_Port.sh ├── String Concatenate.sh ├── Archive-and-encrypt.sh ├── Header-creator.sh ├── String Length Calculator.sh ├── Email Sender.sh ├── Spinner-Loader.sh ├── Factorial_Finder.sh ├── Directory_Existence.sh ├── Get-Temperature.sh ├── Empty_trash.sh ├── Memory-Checker.sh ├── Number-Table.sh ├── Convert-to-lower-case.sh ├── Palindrome-checker.sh ├── Create-iso.sh ├── DateTime.sh ├── Sub-scan.sh ├── Armstrong.sh ├── CPU-usage.sh ├── Number Comparer.sh ├── Password.sh ├── README.md ├── Basic Calculator.sh ├── Check-ubuntu.sh ├── Template-logging.sh ├── Read-Menu.sh ├── Celsius - Farenheit Converter.sh ├── Git-change-author.sh ├── Compare_Versions.sh ├── Decimal-Binary.sh ├── Git_http_to_ssh.sh ├── Template-multihostexec.sh ├── Inactive-branches.sh ├── Backup.sh ├── While-Menu.sh ├── DB Login.sh ├── LICENSE ├── Pomodoro.sh ├── Setup_bashrc.sh ├── Git_Functions.sh └── Network-info.sh /File Reader/file.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /Line-counter.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | wc -l ./* 3 | -------------------------------------------------------------------------------- /Decimal-to-hex.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | printf "0x%x\n" "$1" 3 | -------------------------------------------------------------------------------- /Uptime.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | uptime | sed -le 's/^.*: \(.*\)$/\1/' 3 | -------------------------------------------------------------------------------- /List-dir.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -- * 3 | for i; do 4 | echo "$i" 5 | done 6 | -------------------------------------------------------------------------------- /Check_Directory_Size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo -n "Enter directory: " 3 | read -r x 4 | du -sh "$x" 5 | -------------------------------------------------------------------------------- /File Deleter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Insert a filename to delete" 3 | read filename 4 | rm -i $filename 5 | -------------------------------------------------------------------------------- /Directory_Change.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Enter the name of the directory: " 3 | read CHDIR 4 | cd $CHDIR 5 | -------------------------------------------------------------------------------- /Nmap-find-hostname.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | nmap -sn $1 -oG - | awk '$4=="Status:" && $5=="Up" {print $2, $3}' 3 | -------------------------------------------------------------------------------- /Sleep_Examples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo “Please wait for a few seconds...” 3 | sleep 5 4 | echo “Thank you for your patience.” 5 | -------------------------------------------------------------------------------- /Present Working Directory.sh: -------------------------------------------------------------------------------- 1 | clear 2 | echo "Present working directory is:" 3 | pwd 4 | echo "Number of files is:" 5 | pwd | ls | wc –l -------------------------------------------------------------------------------- /String Slicer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | Str="NetFruit Technologies & TouchScreen BlueTooth Machines" 3 | subStr=${Str:0:20} 4 | echo $subStr 5 | -------------------------------------------------------------------------------- /Conversation Starter.sh: -------------------------------------------------------------------------------- 1 | clear 2 | 3 | read -p "May I know your name, please? " name 4 | echo "Hello $name, let us be friends!" 5 | echo "" -------------------------------------------------------------------------------- /File Reader/File Reader.sh: -------------------------------------------------------------------------------- 1 | #!usr/bin/env bash 2 | file="file.txt" 3 | while read -r line; do 4 | echo -e "$line\n" 5 | done <$file 6 | -------------------------------------------------------------------------------- /Random-emoji.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | while true; do 3 | rand=$(shuf -i 2600-2700 -n 1) 4 | echo -en " \u$rand" 5 | sleep 1 6 | done 7 | -------------------------------------------------------------------------------- /Convert_Videos_Directory_to_MP4.sh: -------------------------------------------------------------------------------- 1 | $ for INPUT in *.avi ; do echo "${INPUT%.avi}" ; done | xargs -i -P9 HandBrakeCLI -i "{}".avi -o "{}".mp4 2 | -------------------------------------------------------------------------------- /File Generator.sh: -------------------------------------------------------------------------------- 1 | echo "What is the name of your file?" 2 | read FILE 3 | echo "This file will be created as ${FILE}_file." 4 | touch ${FILE}_file -------------------------------------------------------------------------------- /Clear-cache.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | days="$1" 3 | if [ -z "$days" ]; then 4 | days=3 5 | fi 6 | find ~/.cache -depth -type f -mtime +"$days" -delete 7 | -------------------------------------------------------------------------------- /Scan_Open_Port.sh: -------------------------------------------------------------------------------- 1 | $ for i in {1..65535}; do (echo < /dev/tcp/127.0.0.1/$i) &>/dev/null && printf "\n[+] Open port at\n: \t%d\n" "$i" || printf "."; done 2 | -------------------------------------------------------------------------------- /String Concatenate.sh: -------------------------------------------------------------------------------- 1 | clear 2 | echo "Enter two strings: " 3 | read "str1" 4 | read "str2" 5 | str3=`echo $str1 $str2` 6 | echo after concatenate : $str3 -------------------------------------------------------------------------------- /Archive-and-encrypt.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | name=$1 3 | path=$2 4 | tar -czvf "$name.tar.gz" "$path" 5 | gpg -c "$name.tar.gz" 6 | rm -rf "$name.tar.gz" 7 | -------------------------------------------------------------------------------- /Header-creator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | for f in *.cpp; do 3 | echo Processing $f 4 | cat header $f > $f.new 5 | mv $f.new $f 6 | done 7 | echo Process finished 8 | -------------------------------------------------------------------------------- /String Length Calculator.sh: -------------------------------------------------------------------------------- 1 | clear 2 | echo "Enter string: " 3 | read "str" 4 | len=`echo $str | wc -c` 5 | len=`expr $len - 1` 6 | echo "Length of string = $len" -------------------------------------------------------------------------------- /Email Sender.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | Recipient=”Hello@example.com” 3 | Subject=”Greetings” 4 | Message=”Welcome to OnBoard Devs” 5 | `mail -s $Subject $Recipient <<< $Message` 6 | -------------------------------------------------------------------------------- /Spinner-Loader.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | arr=('-' '\' '|' '/') 3 | while true; do 4 | for c in "${arr[@]}"; do 5 | echo -en "\r $c " 6 | sleep .5 7 | done 8 | done 9 | -------------------------------------------------------------------------------- /Factorial_Finder.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo -n "Enter number: " 3 | read -r a 4 | fact=1 5 | while [ "$a" -ne 0 ]; do 6 | fact=$((fact * a)) 7 | a=$((a - 1)) 8 | done 9 | echo $fact 10 | -------------------------------------------------------------------------------- /Directory_Existence.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Enter directory name: " 3 | read ndir 4 | if [ -d "$ndir" ] 5 | then 6 | echo "Directory exists." 7 | else 8 | `mkdir $ndir` 9 | echo "Directory created!" 10 | fi 11 | -------------------------------------------------------------------------------- /Get-Temperature.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | TEMP_FILE=/sys/class/thermal/thermal_zone0/temp 3 | ORIGINAL_TEMP=$(cat $TEMP_FILE) 4 | TEMP_C=$((ORIGINAL_TEMP/1000)) 5 | TEMP_F=$(($TEMP_C * 9/5 + 32)) 6 | echo $TEMP_F F 7 | -------------------------------------------------------------------------------- /Empty_trash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | [ -d ~/.local/share/Trash ] && rm -rf ~/.local/share/Trash/* && echo "Emptied shared trash." 3 | [ -d ~/.Trash ] && rm -rf ~/.Trash/* && echo "Emptied trash." # For Mac and some other systems. 4 | -------------------------------------------------------------------------------- /Memory-Checker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | phymem="$(free | awk '/^Mem:/{print $2}')" 3 | [ -z "$phymem" ] && phymem=0 4 | if [ "$phymem" -lt 1000000 ]; then 5 | echoerr "A minimum of 1024 MB RAM is required." 6 | exit 1 7 | fi 8 | -------------------------------------------------------------------------------- /Number-Table.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo -n "Enter the number upto which you want to print a table: " 3 | read -r n 4 | i=1 5 | while [ $i -ne 10 ]; do 6 | i=$((i + 1)) 7 | table=$((i * n)) 8 | echo "$table" 9 | done 10 | -------------------------------------------------------------------------------- /Convert-to-lower-case.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo -n "Enter file name: " 3 | read -r file 4 | if [ ! -f "$file" ]; then 5 | echo "Filename $file does not exist." 6 | exit 1 7 | fi 8 | tr '[:upper:]' '[:lower:]' < "$file" >> small.txt 9 | -------------------------------------------------------------------------------- /Palindrome-checker.sh: -------------------------------------------------------------------------------- 1 | read palindrome 2 | reverse=$( echo $palindrome | rev ) 3 | if [ $palindrome = $reverse ]; then  4 | echo "The number you provided is a palindrome." 5 | else 6 | echo "The number you provided is not a palindrome." 7 | fi 8 | -------------------------------------------------------------------------------- /Create-iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z "$1" ]; then 3 | LABEL="bootable" 4 | else 5 | LABEL=$1 6 | fi 7 | echo "Creating ISO..." 8 | mkisofs -o disk.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V $LABEL iso_root 9 | -------------------------------------------------------------------------------- /DateTime.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | Year=`date +%Y` 3 | Month=`date +%m` 4 | Day=`date +%d` 5 | Hour=`date +%H` 6 | Minute=`date +%M` 7 | Second=`date +%S` 8 | echo `date` 9 | echo "Today's date is: $Day-$Month-$Year" 10 | echo "Current time: $Hour:$Minute:$Second" 11 | -------------------------------------------------------------------------------- /Sub-scan.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | IPPFX=$1 3 | for i in `seq 1 255` ; do LIST="$LIST ${IPPFX}.$i" ; done 4 | for i in $LIST ; do 5 | ENTRY="`host $i`" 6 | [ $? -ne 0 ] && continue 7 | ENTRY=`echo "$ENTRY" l sed -e 's/.* //' -e 's/\.$//'` 8 | echo -e "$i\t$ENTRY" 9 | done 10 | -------------------------------------------------------------------------------- /Armstrong.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo -n "Enter number: " 3 | read -r n 4 | arm=0 5 | temp=$n 6 | while [ "$n" -ne 0 ]; do 7 | r=$((n % 10)) 8 | arm=$((arm + r * r * r)) 9 | n=$((n / 10)) 10 | done 11 | echo $arm 12 | if [ $arm -eq "$temp" ]; then 13 | echo "Armstrong" 14 | else 15 | echo "Not armstrong" 16 | fi 17 | -------------------------------------------------------------------------------- /CPU-usage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | main() { 3 | local prefix 4 | cpu_usage_total=$(top -b -n2 -p 1 | grep -F "Cpu(s)" | tail -1 | awk -F'id,' -v prefix="$prefix" '{ split($1, vs, ","); v=vs[length(vs)]; sub("%", "", v); printf "%s%.1f%%\n", prefix, 100 - v }') 5 | echo "Total CPU usage: $cpu_usage_total" 6 | } 7 | main "$@" 8 | -------------------------------------------------------------------------------- /Number Comparer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | echo "Enter values for A, B & C." 4 | read "A" 5 | read "B" 6 | read "C" 7 | if test $A -gt $B -a $A -gt $C; 8 | then 9 | echo "A is the greatest." 10 | else 11 | if test $B -gt $cC; 12 | then 13 | echo "B is the greatest." 14 | else 15 | echo "C is the greatest." 16 | fi 17 | fi 18 | -------------------------------------------------------------------------------- /Password.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | password="" 3 | echo "Enter Username: " 4 | read username 5 | pass_var="Enter Password: " 6 | while IFS= read -p "$pass_var" -r -s -n 1 letter 7 | do 8 | if [[ $letter == $'\0' ]] 9 | then 10 | break 11 | fi 12 | password=password+"$letter" 13 | pass_var="*" 14 | done 15 | echo 16 | echo "Your password has been read with an asterisk (*)." 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unix Scripts 2 | 3 | A collection of handy Shell scripts to improve the way you use your computers. 4 | 5 | Big thanks to the following websites for a few of the scripts: 6 | 7 | - https://www.shellscript.sh/index.html 8 | - https://regex101.com/ 9 | - https://www.gnu.org/software/bash/manual/html_node/index.html 10 | - https://www.fosslinux.com/46250/35-bash-script-examples.htm 11 | -------------------------------------------------------------------------------- /Basic Calculator.sh: -------------------------------------------------------------------------------- 1 | echo "Enter two numbers:" 2 | read a 3 | read b 4 | echo "Enter choice:" 5 | echo "1. Addition" 6 | echo "2. Subtraction" 7 | echo "3. Multiplication" 8 | echo "4. Division" 9 | read ch 10 | case $ch in 11 | 1)res=`echo $a + $b | bc` 12 | ;; 13 | 2)res=`echo $a - $b | bc` 14 | ;; 15 | 3)res=`echo $a \* $b | bc` 16 | ;; 17 | 4)res=`echo "scale=2; $a / $b" | bc` 18 | ;; 19 | esac 20 | echo "Result : $res" -------------------------------------------------------------------------------- /Check-ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | os_type="$(lsb_release -si 2>/dev/null)" 3 | if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ]; then 4 | echoerr "Only supports Ubuntu/Debian." 5 | exit 1 6 | fi 7 | if [ "$os_type" = "Ubuntu" ]; then 8 | os_ver="$(lsb_release -sr)" 9 | if [ "$os_ver" != "16.04" ] && [ "$os_ver" != "14.04" ] && [ "$os_ver" != "12.04" ]; then 10 | echoerr "Only supports Ubuntu 12.04/14.04/16.04." 11 | exit 1 12 | fi 13 | fi 14 | -------------------------------------------------------------------------------- /Template-logging.sh: -------------------------------------------------------------------------------- 1 | export DEBUG_FLAG=1 2 | Log_Info() { 3 | local timestamp=`date +"%Y%m%d%H%M%S"` 4 | log_message="$timestamp INFO: $1" 5 | test $DEBUG_FLAG -eq 1 && echo "$log_message" 6 | } 7 | Log_Error() { 8 | local timestamp=`date +"%Y%m%d%H%M%S"` 9 | log_message="$timestamp ERROR: $1" 10 | echo "$log_message" 1>&2; 11 | } 12 | Log_Error "This is an error message. Ideally I should be followed by a exit ." 13 | Log_Info "For your info, I am an info message." 14 | -------------------------------------------------------------------------------- /Read-Menu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | clear 3 | cat << EOF 4 | Please Select: 5 | 1. Display System Information 6 | 2. Display Disk Space 7 | 3. Display Home Space Utilization 8 | 0. Quit 9 | EOF 10 | echo -n 'Enter selection [0-3]: ' 11 | read -r sel 12 | case $sel in 13 | 0) echo "Program terminated.";; 14 | 1) echo "Hostname: $HOSTNAME"; uptime;; 15 | 2) df -h;; 16 | 3) 17 | if [ "$UID" = 0 ]; then 18 | echo "Home Space Utilization (All Users)" 19 | du -sh /home/* 20 | else 21 | echo "Home Space Utilization ($USER)" 22 | du -sh "$HOME" 23 | fi 24 | ;; 25 | *) 26 | echo "Invalid entry." >&2 27 | exit 1 28 | esac 29 | -------------------------------------------------------------------------------- /Celsius - Farenheit Converter.sh: -------------------------------------------------------------------------------- 1 | echo "*** Converting between different temperature units ***" 2 | echo "1. Convert Celsius temperatures into Fahrenheit" 3 | echo "2. Convert Fahrenheit temperatures into Celsius" 4 | echo -n "Select your choice (1-2): " 5 | read choice 6 | 7 | if [ $choice -eq 1 ] 8 | then 9 | echo -n "Enter temperature (C): " 10 | read tc 11 | tf=$(echo "scale=2;((9/5) * $tc) + 32" |bc) 12 | echo "$tc C = $tf F" 13 | elif [ $choice -eq 2 ] 14 | then 15 | echo -n "Enter temperature (F): " 16 | read tf 17 | tc=$(echo "scale=2;(5/9)*($tf-32)"|bc) 18 | echo "$tf = $tc" 19 | else 20 | echo "Please select 1 or 2 only" 21 | exit 1 22 | fi 23 | -------------------------------------------------------------------------------- /Git-change-author.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ -z "$1" || "$1" == "--help" || -z "$2" ]]; then 3 | echo ' Usage: git-change-author "Your Name" "email@address" [SHA1]' 4 | exit 1 5 | fi 6 | AUTHOR="$1" 7 | EMAIL="$2" 8 | START_HASH="${3:---root}" 9 | echo "On the next screen, you need to change 'pick' to 'edit' for every commit which you wish to alter." 10 | echo "" 11 | echo -n "Press ENTER to continue." 12 | read 13 | git rebase --rebase-merges -i ${START_HASH} 14 | while [ "$?" -eq 0 ]; do 15 | git -c user.name="${AUTHOR}" -c user.email="${EMAIL}" commit --amend --no-edit --author "${AUTHOR} <${EMAIL}>" 16 | git rebase --continue 17 | done 18 | git rebase --rebase-merges --committer-date-is-author-date "${START_HASH}" 19 | echo "" 20 | echo "" 21 | echo "Don't forget to run \`git push -f\` - preferably on a test branch first!" 22 | -------------------------------------------------------------------------------- /Compare_Versions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | VERSION=$1 3 | VERSION2=$2 4 | function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; } 5 | function version_le() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" == "$1"; } 6 | function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; } 7 | function version_ge() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"; } 8 | if version_gt $VERSION $VERSION2; then 9 | echo "$VERSION is greater than $VERSION2." 10 | fi 11 | if version_le $VERSION $VERSION2; then 12 | echo "$VERSION is less than or equal to $VERSION2." 13 | fi 14 | if version_lt $VERSION $VERSION2; then 15 | echo "$VERSION is less than $VERSION2." 16 | fi 17 | if version_ge $VERSION $VERSION2; then 18 | echo "$VERSION is greater than or equal to $VERSION2." 19 | fi 20 | -------------------------------------------------------------------------------- /Decimal-Binary.sh: -------------------------------------------------------------------------------- 1 | main() { 2 | if [ $# -ne 1 ]; then 3 | echo "You must provide only 1 number." 4 | exit 1 5 | fi 6 | re='^[0-9]+$' 7 | if ! [[ $1 =~ $re ]]; then 8 | echo "$1 is not a positive integer." 9 | exit 1 10 | fi 11 | echo "Conversion of a decimal number $1 to its binary representation." 12 | number=$1 13 | reminder=1 14 | binary_representation=" " 15 | while [ "$number" -gt 0 ] 16 | do 17 | reminder=$(( number % 2)) 18 | binary_representation="$binary_representation$reminder" 19 | number=$(( number / 2)) 20 | done 21 | i=${#binary_representation} 22 | result=" " 23 | while [ "$i" -gt 0 ] 24 | do 25 | rev=$(echo "$binary_representation" | awk '{ printf substr( $0, "$i",1 ) }') 26 | result="$result$rev" 27 | i=$(( i - 1 )) 28 | done 29 | echo "Binary representation: $result" 30 | } 31 | main "$@" 32 | -------------------------------------------------------------------------------- /Git_http_to_ssh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function git_http_to_ssh { 3 | local name=${1} 4 | local name=${name:=origin} 5 | local url=$( git remote get-url $name ) 6 | [[ "$url" =~ (http[s]?)://(.+)/(.+)/(.+)(\.git)? ]] 7 | local protocol="${BASH_REMATCH[1]}" 8 | if [ \( "$protocol" == "http" \) -o \( "$protocol" == "https" \) ] ;then 9 | local provider="${BASH_REMATCH[2]}" 10 | local team="${BASH_REMATCH[3]}" 11 | local prj="${BASH_REMATCH[4]}" 12 | local ext="${BASH_REMATCH[5]}" 13 | company=$(fgrep Host ~/.ssh/config | fgrep -v Hostname | cut -d' ' -f2) 14 | if [ X"${company}" != "X" -a X"${provider}" == "Xbitbucket.org" -a -f "~/.ssh/id_rsa_${team}" ] ;then 15 | provider="${company}" 16 | fi 17 | git remote set-url $name "git@${provider}:${team}/${prj}${ext}" 18 | git remote set-url --push $name "git@${provider}:${team}/${prj}${ext}" 19 | fi 20 | } 21 | git_http_to_ssh $@ 22 | -------------------------------------------------------------------------------- /Template-multihostexec.sh: -------------------------------------------------------------------------------- 1 | MULTIHOSTEXEC_HOSTLIST_FILE=template-multihost-hosts.lst 2 | nHostListCount=`grep -v "^$\|#" $MULTIHOSTEXEC_HOSTLIST_FILE 2>/dev/null | wc -l` 3 | arrHostList=`grep -v "^$\|#" $MULTIHOSTEXEC_HOSTLIST_FILE 2>/dev/null` 4 | if [ ! -s $MULTIHOSTEXEC_HOSTLIST_FILE -o ! -r $MULTIHOSTEXEC_HOSTLIST_FILE -o $nHostListCount -eq 0 ]; then 5 | echo "Error: Cannot read host file/file is empty." 6 | exit 1 7 | fi 8 | echo "Found $nHostListCount hosts." 9 | nHostIndex=0 10 | for nHost in $arrHostList 11 | do 12 | nHostIndex=`expr $nHostIndex + 1` 13 | echo "Processing [$nHostIndex of $nHostListCount] $nHost." 14 | ssh -q -T $nHost <<-'ENDSSH' 15 | ENDSSH 16 | strRemoteFileName="/some/remote-folder/*$(date +%Y%m%d).tar.gz" 17 | echo "On LOCAL - Downloading remote file $nHost:$strRemoteFileName $strRemoteFileName." 18 | scp -q $nHost:$strRemoteFileName 19 | test $? && echo "On LOCAL - File download complete!" 20 | done 21 | echo "Complete!" 22 | -------------------------------------------------------------------------------- /Inactive-branches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "Enter repository to check inactive branches: " 3 | read repo_name 4 | echo "Enter username: " 5 | read user_name 6 | echo "Enter password: " 7 | read -s password 8 | presentdate=`date +'%s'` 9 | list_of_branches=$(curl -s -u $user_name:$password https://api.github.com/repos/$user_name/$repo_name/branches | jq '.[].name') 10 | for branch in $list_of_branches; do  11 | api_branch_name=$(echo $branch | cut -d'"' -f 2) 12 | last_updated_date=$(curl -s -u $user_name:$password https://api.github.com/repos/$user_name/$repo_name/branches/$api_branch_name | jq '.commit.commit.author.date') 13 | api_last_updated_date=$(echo $last_updated_date | cut -d'"' -f 2) 14 | last_updated_date_sec=$(date -d $api_last_updated_date +%s) 15 | numberofdays=$(( ($presentdate - $last_updated_date_sec)/(60*60*24) )) 16 | if [ $numberofdays -gt 60 ] ; then 17 |        echo "Branch $api_branch_name was last updated $numberofdays days ago." 18 |     fi 19 | done 20 | -------------------------------------------------------------------------------- /Backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Code from http://samba.anu.edu.au/rsync/examples.html 3 | # You will end up with a 7 day rotating incremental backup. 4 | BDIR=$HOME 5 | EXCLUDES=$HOME/local/etc/backup_exclude 6 | BLOCATION=/Volumes/Storage/Backups 7 | SCRIPTS_DIR=$HOME/local/etc/backup.d 8 | if [[ -d $SCRIPTS_DIR ]] 9 | then 10 | for file in `ls $SCRIPTS_DIR` 11 | do 12 | $SCRIPTS_DIR/$file $BDIR 2> /dev/null > /dev/null 13 | if (( $? != 0 )) 14 | then 15 | ERRCODE=$? 16 | echo Execution of script $SCRIPTS_DIR/$file failed. 17 | exit $? 18 | fi 19 | done 20 | fi 21 | BACKUPDIR=`date +%A` 22 | OPTS="--extended-attributes --force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES 23 | --delete --times --backup --backup-dir=../$BACKUPDIR -a" 24 | [ -d $HOME/emptydir ] || mkdir $HOME/emptydir 25 | rsync --delete -a $HOME/emptydir/ $BLOCATION/$USER/$BACKUPDIR/ 26 | rmdir $HOME/emptydir 27 | rsync $OPTS $BDIR $BLOCATION/$USER/current 28 | -------------------------------------------------------------------------------- /While-Menu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DELAY=1 3 | while true; do 4 | clear 5 | cat << EOF 6 | Please Select: 7 | 1. Display System Information 8 | 2. Display Disk Space 9 | 3. Display Home Space Utilization 10 | 0. Quit 11 | EOF 12 | read -p "Enter selection [0-3] > " 13 | case "$REPLY" in 14 | 0) 15 | break 16 | ;; 17 | 1) 18 | echo "Hostname: $HOSTNAME" 19 | uptime 20 | ;; 21 | 2) 22 | df -h 23 | ;; 24 | 3) 25 | if [[ $(id -u) -eq 0 ]]; then 26 | echo "Home Space Utilization (all users)" 27 | du -sh /home/* 28 | else 29 | echo "Home Space Utilization ($USER)" 30 | du -sh $HOME 31 | fi 32 | ;; 33 | *) 34 | echo "Invalid entry." 35 | ;; 36 | esac 37 | sleep "$DELAY" 38 | done 39 | echo "Program terminated." 40 | -------------------------------------------------------------------------------- /DB Login.sh: -------------------------------------------------------------------------------- 1 | # DB Log-in using PasswordSafe for different regions 2 | #!/bin/bash 3 | #Usage 4 | echo 'On command line run ./db_login.sh ' 5 | echo 'Example region is LDN or TKY or DEV' 6 | echo 'account_number is just the safe account' 7 | echo 'password is the password copied from Safe page' 8 | 9 | if [ $# -ne 3 ] 10 | then 11 | echo 'Usage:./db_login.sh ' 12 | exit 1 13 | fi 14 | #LDN 15 | if [ $1 == 'LDN' ] 16 | then 17 | #LDN 18 | user=$2 19 | pass=$3 20 | dbName=$1 21 | elif [ $1 == 'TKY' ] 22 | then 23 | #TKY 24 | user=$2 25 | pass=$3 26 | dbName=$1 27 | elif [ $1 == 'DEV' ] 28 | then 29 | #DEV 30 | user=$2 31 | pass=$3 32 | dbName=$1 33 | fi 34 | #LDN connection string 35 | echo '------------------------------------------------------------------' 36 | echo "Database: $dbName" 37 | echo "Account user $user" 38 | while true; do 39 | read -p 'Do you wish to continue? ' yn 40 | case $yn in 41 | [Yy]* ) break;; 42 | [Nn]* ) exit;; 43 | * ) echo 'Please answer yes or no.';; 44 | esac 45 | done 46 | connection_string="sqsh -S $dbName -U $user -P $pass" 47 | echo 'Running '$connection_string'...' 48 | exec $connection_string 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Pomodoro.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wseconds=${1:-25}*60; 3 | pseconds=${2:-wseconds/300}*60; 4 | if [ "$(uname)" == "CodeMaster7000" ]; then 5 | while true; do 6 | date1=$((`date +%s` + $wseconds)); 7 | while [ "$date1" -ge `date +%s` ]; do 8 | echo -ne "$(date -u -j -f %s $(($date1 - `date +%s`)) +%H:%M:%S)\r"; 9 | done 10 | osascript -e 'display notification "Break"'; 11 | read -n1 -rsp $'Press any key to continue (Ctrl+C to exit)\n'; 12 | date2=$((`date +%s` + $pseconds)); 13 | while [ "$date2" -gt `date +%s` ]; do 14 | echo -ne "$(date -u -j -f %s $(($date2 - `date +%s`)) +%H:%M:%S)\r"; 15 | done 16 | osascript -e 'display notification "Work"'; 17 | read -n1 -rsp $'Press any key to continue (Ctrl+C to exit)\n'; 18 | done 19 | elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 20 | while true; do 21 | date1=$((`date +%s` + $wseconds)); 22 | while [ "$date1" -ge `date +%s` ]; do 23 | echo -ne "$(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r"; 24 | done 25 | notify-send "Break"; 26 | read -n1 -rsp $'Press any key to continue (Ctrl+C to exit)\n'; 27 | date2=$((`date +%s` + $pseconds)); 28 | while [ "$date2" -ge `date +%s` ]; do 29 | echo -ne "$(date -u --date @$(($date2 - `date +%s` )) +%H:%M:%S)\r"; 30 | done 31 | notify-send "Work"; 32 | read -n1 -rsp $'Press any key to continue (Ctrl+C to exit)\n'; 33 | done 34 | else 35 | echo -ne "Your OS is not supported.\n"; 36 | fi 37 | -------------------------------------------------------------------------------- /Setup_bashrc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ "$0" == "$BASH_SOURCE" ]; then 3 | echo >&2 "Setup script has to be sourced, not run with sh. Aborting..." 4 | exit 1 5 | fi 6 | if [ ! -e ~/.sp ] ; then 7 | touch ~/.sp 8 | fi 9 | if [ $(uname -o) == "Cygwin" ]; then 10 | (set -o igncr) 2>/dev/null && set -o igncr; 11 | fi 12 | echo " 13 | ################################################################################ 14 | #Hide user name and host in terminal 15 | #export PS1="\w$ " 16 | #Make ls every time a terminal opens 17 | ls 18 | #cd + ls 19 | function cs () { 20 | cd \$1 21 | ls -a 22 | } 23 | #transfer path: save the current path to a hidden file 24 | function tp () { 25 | pwd > ~/.sp 26 | } 27 | #goto transfer path: goes where the previously saved tp points 28 | function gtp () { 29 | cs \`cat ~/.sp\` 30 | } 31 | #cat with color 32 | function ccat () { 33 | source-highlight -fesc -i \$1 34 | } 35 | #Remove trash from terminal and runs program in background 36 | function evince () { 37 | /usr/bin/evince \$* 2> /dev/null & disown 38 | } 39 | function gedit (){ 40 | /usr/bin/gedit \$* 2> /dev/null & disown 41 | } 42 | # up N: moves N times upwards (cd ../../../{N}) 43 | function up () { 44 | LIMIT=\$1 45 | P=\$PWD 46 | for ((i=1; i <= LIMIT; i++)) 47 | do 48 | P=\$P/.. 49 | done 50 | cs \$P 51 | export MPWD=\$P 52 | } 53 | " >> ~/.bashrc 54 | source ~/.bashrc 55 | if [ $(uname -o) == "Cygwin" ]; then 56 | if [ command -v dos2unix >/dev/null 2>&1 ]; then 57 | dos2unix $INTENDED_BASH_PATH 58 | fi 59 | fi 60 | if [ ! -f ~/.bash_profile ]; then 61 | echo ".bash_profile not found. Creating..." 62 | echo " 63 | # include .bashrc if it exists 64 | if [ -f "\$HOME/.bashrc" ]; then 65 | . "\$HOME/.bashrc" 66 | fi 67 | " > ~/.bash_profile 68 | fi 69 | echo ".bashrc updated!" 70 | -------------------------------------------------------------------------------- /Git_Functions.sh: -------------------------------------------------------------------------------- 1 | function delete_gone_branches() { 2 | if [[ "$#" -ne 1 ]]; then 3 | echo "Exactly one argument needed: path to the directory." 4 | return 1 5 | fi 6 | dir=${1} 7 | make_heading ${dir} 8 | if [[ ! -d ${dir} ]]; then 9 | echo "${dir} is not a valid path." 10 | return 1 11 | fi 12 | if [[ ${dir} != '.' ]]; then 13 | pushd ${dir} 14 | fi 15 | if [[ -d .git ]]; then 16 | git fetch -p 17 | git branch -v | grep gone | awk -F' ' '{print $1}' | xargs -I{} -P 4 -- git branch -D {} 18 | else 19 | echo "It is not a git repository." 20 | fi 21 | if [[ ${dir} != '.' ]]; then 22 | popd 23 | fi 24 | } 25 | function removeBranchesFromRemote() { 26 | padding=" " 27 | date=$(gum input --value $(date '+%Y-%m-%d') --placeholder "Older than?") 28 | if [[ -z "$date" ]]; then 29 | echo "Date cannot be empty." 30 | return 31 | fi 32 | old_branches="" 33 | function populateOldBranches() { 34 | for remote_branch in $(git branch -r | grep -v "HEAD\|develop\|master\|main\|release*" | sed /\*/d); do 35 | if [[ -z "$(git log -1 --since=\"${date}\" -s ${remote_branch})" ]]; then 36 | author=$(git show --format="%an" ${remote_branch} | head -n 1) 37 | age=$(git show --format="%cr" ${remote_branch} | head -n 1) 38 | branch=$(echo ${remote_branch} | sed 's#origin/##') 39 | old_branches+='\n'$(printf "%s|%s|%s\n" \ 40 | "${author}${padding:${#author}}" \ 41 | "${age}${padding:${#age}}" \ 42 | "${branch}") 43 | fi 44 | done 45 | } 46 | populateOldBranches 47 | if [[ -n $old_branches ]]; then 48 | branchesToBeDeleted=$(echo $old_branches | gum choose --no-limit | awk -F'|' '{print $3}') 49 | if [[ -n $branchesToBeDeleted ]]; then 50 | echo $branchesToBeDeleted 51 | gum confirm "Delete aforementioned branches from remote?" && 52 | echo $branchesToBeDeleted | xargs -P 8 -I{} -- git push origin --delete {} 53 | fi 54 | else 55 | echo "No branch older than ${date} found." 56 | fi 57 | } 58 | -------------------------------------------------------------------------------- /Network-info.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | IP4FW=/sbin/iptables 3 | IP6FW=/sbin/ip6tables 4 | LSPCI=/usr/bin/lspci 5 | ROUTE=/sbin/route 6 | NETSTAT=/bin/netstat 7 | LSB=/usr/bin/lsb_release 8 | DNSCLIENT="/etc/resolv.conf" 9 | DRVCONF="/etc/modprobe.conf" 10 | NETALIASCFC="/etc/sysconfig/network-scripts/ifcfg-eth?-range?" 11 | NETCFC="/etc/sysconfig/network-scripts/ifcfg-eth?" 12 | NETSTATICROUTECFC="/etc/sysconfig/network-scripts/route-eth?" 13 | SYSCTL="/etc/sysctl.conf" 14 | OUTPUT="network.$(date +'%d-%m-%y').info.txt" 15 | SUPPORT_ID="your_name@service_provider.com" 16 | chk_root() { 17 | local meid="$(id -u)" 18 | if [ "$meid" -ne 0 ]; then 19 | echo "You must be root user to run this tool." 20 | exit 999 21 | fi 22 | } 23 | write_header() { 24 | echo "---------------------------------------------------" >>"$OUTPUT" 25 | echo "$@" >>"$OUTPUT" 26 | echo "---------------------------------------------------" >>"$OUTPUT" 27 | } 28 | dump_info() { 29 | echo "* Hostname: $(hostname)" >"$OUTPUT" 30 | echo "* Run date and time: $(date)" >>"$OUTPUT" 31 | write_header "Linux Distro" 32 | echo "Linux kernel: $(uname -mrs)" >>"$OUTPUT" 33 | "$LSB" -a >>"$OUTPUT" 34 | [ -x "$HWINF" ] && write_header "$HWINF" 35 | [ -x "$HWINF" ] && "$HWINF" >>"$OUTPUT" 36 | [ -x "$HWINF" ] && write_header "$HWINF" 37 | [ -x "$HWINF" ] && "$HWINF" >>"$OUTPUT" 38 | write_header "PCI Devices" 39 | "$LSPCI" -v >>"$OUTPUT" 40 | write_header "$IFCFG Output" 41 | "$IFCFG" >>"$OUTPUT" 42 | write_header "Kernel Routing Table" 43 | "$ROUTE" -n >>"$OUTPUT" 44 | write_header "Network Card Drivers Configuration $DRVCONF" 45 | [ -f "$DRVCONF" ] && grep eth "$DRVCONF" >>"$OUTPUT" || echo "Error $DRVCONF file not found." >>"$OUTPUT" 46 | write_header "DNS Client $DNSCLIENT Configuration" 47 | [ -f "$DNSCLIENT" ] && cat "$DNSCLIENT" >>"$OUTPUT" || echo "Error $DNSCLIENT file not found." >>"$OUTPUT" 48 | write_header "Network Configuration File" 49 | for f in "$NETCFC"; do 50 | if [ -f "$f" ]; then 51 | echo "** $f **" >>"$OUTPUT" 52 | cat "$f" >>"$OUTPUT" 53 | else 54 | echo "Error $f not found." >>"$OUTPUT" 55 | fi 56 | done 57 | write_header "Network Aliase File" 58 | for f in "$NETALIASCFC"; do 59 | if [ -f "$f" ]; then 60 | echo "** $f **" >>"$OUTPUT" 61 | cat "$f" >>"$OUTPUT" 62 | else 63 | echo "Error $f not found." >>"$OUTPUT" 64 | fi 65 | done 66 | write_header "Network Static Routing Configuration" 67 | for f in "$NETSTATICROUTECFC"; do 68 | if [ -f "$f" ]; then 69 | echo "** $f **" >>"$OUTPUT" 70 | cat "$f" >>"$OUTPUT" 71 | else 72 | echo "Error $f not found." >>"$OUTPUT" 73 | fi 74 | done 75 | write_header "IP4 Firewall Configuration" 76 | "$IP4FW" -L -n >>"$OUTPUT" 77 | write_header "IP6 Firewall Configuration" 78 | "$IP6FW" -L -n >>"$OUTPUT" 79 | write_header "Network Stats" 80 | "$NETSTAT" -s >>"$OUTPUT" 81 | write_header "Network Tweaks via $SYSCTL" 82 | [ -f "$SYSCTL" ] && cat "$SYSCTL" >>"$OUTPUT" || echo "Error $SYSCTL not found." >>"$OUTPUT" 83 | echo "The Network Configuration Info Written To $OUTPUT. Please email this file to $SUPPORT_ID." 84 | } 85 | chk_root 86 | dump_info 87 | --------------------------------------------------------------------------------