From a9edbd22091a2bd63b2e498408dc6abfdf733915 Mon Sep 17 00:00:00 2001 From: thomaspcole Date: Thu, 4 Apr 2019 15:17:26 -0400 Subject: [PATCH] Initial Commit --- ipChecker.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++ visualDiskUsage.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100755 ipChecker.sh create mode 100755 visualDiskUsage.sh diff --git a/ipChecker.sh b/ipChecker.sh new file mode 100755 index 0000000..c4a6788 --- /dev/null +++ b/ipChecker.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +################################################################################ +# A simple script to get the DNS name of an IP and test if its online # +# # +# NOW WITH CONVENIENT CSV FORMAT # +################################################################################ + +PIDS="" + +if [[ -z $1 ]]; then + echo "Invalid Usage" + echo "Example: ./ipChecker.sh ip-list.txt" + exit 1 +fi + +function checkIP() { + #Try and resolve hostname. If none exists report N/A + digIP=$( + record=$(dig -x $1 +short); + if [ -z $record ]; then echo "N/A"; + else echo ${record::-1}; + fi) + + #ping the address and grep for the number of received packets. This is 0 if it does not ping + pingIP=$(ping -c 5 -i 0.2 -w 0.5 $1 | grep -i received | awk '{print $4}') + + #if the PingIP variable is 0 then the address does not ping. + if [[ 0 -eq $pingIP ]]; then + doesPing="NO" + else + doesPing="YES" + fi + + printf "%s,%s,%s\n" $1 $digIP $doesPing +} + +echo "IP,DNS Entry,Is Online" +#read each line in the file passed as the first arguement +while read ip; do + checkIP $ip & + PIDS+="$! " +done < $1 + +for pid in $PIDS; do + wait $pid +done diff --git a/visualDiskUsage.sh b/visualDiskUsage.sh new file mode 100755 index 0000000..e630c87 --- /dev/null +++ b/visualDiskUsage.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +################################################################################ +# A simple script to print out disk usage of a given volume # +# # +# Add the path of additional disks in the DIRS variable # +################################################################################ + +DIRS=('/dev/sda1' '/dev/sda2') + +echo "" +for dir in ${DIRS[@]}; do + stats=$(df -h $dir) + + if [[ -z $stats ]]; then + continue + fi + + drivePerc=$(echo $stats | awk '{ print $12 }' | tr -d %) + fillPerc=$(( $drivePerc / 2 )) + spacingChar=$(( 50 - $fillPerc )) + + echo $dir + + echo -n "[" + + for (( i = 0; i < fillPerc; i++ )); do + echo -n "#" + done + + for (( i = 0; i < spacingChar; i++ )); do + echo -n "-" + done + + echo "] "$drivePerc"%" + echo "" + +done