aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/Backup91
-rwxr-xr-xbin/lamp15
-rwxr-xr-xbin/ping_subnet33
3 files changed, 139 insertions, 0 deletions
diff --git a/bin/Backup b/bin/Backup
new file mode 100755
index 0000000..a627fd9
--- /dev/null
+++ b/bin/Backup
@@ -0,0 +1,91 @@
+#!/bin/bash
+destination="jmbp@192.168.32.102::jmbp"
+backupPaths=("Desktop" "Movies" "Music" "Documents" "Pictures" "_code" "Google Drive")
+
+spinner() {
+ tput sc; tput setaf 3
+ i=1
+ sp="/-\|"
+ echo -n ' '
+ while kill -0 $1 2> /dev/null
+ do
+ sleep 0.1
+ printf "\b${sp:i++%${#sp}:1}"
+ done
+ tput sgr0; tput rc; tput el
+}
+clearLines() {
+ tput sc
+ for i in 1 2 3 4
+ do
+ printf "\n"
+ tput ed
+ tput el
+ done
+ tput rc
+}
+
+tput civis
+
+mtmpdir=$(mktemp -d)
+printf "Directory for log files: '$mtmpdir'.\n"
+
+# Run rsync on all the directories
+error=false
+for path in "${backupPaths[@]}"; do
+ # Just print the status-text
+ tput setaf 4
+ printf "\n%-22s" "$main$path..."
+ tput sc; tput setaf 8
+ printf "\n(tail -f \"$mtmpdir/$path.log\")"
+ tput sgr0; tput rc; tput el
+
+ # Actually start rsync for the directory
+ rsync -az --info=all --log-file="$mtmpdir/$path.log" "$path" "$destination" &> /dev/null &
+ rsyncPID=$!
+ trap "kill $rsyncPID 2> /dev/null" EXIT
+ spinner $rsyncPID
+
+ # Catch rsync's exit code by using wait on a dead PID and hope for the best
+ wait $rsyncPID
+ rsyncExitCode=$?
+
+ # Clear a few lines to get rid of the temporary tail command string
+ clearLines
+
+ # Print final status of the rsync command
+ if [ "$rsyncExitCode" -eq "0" ]
+ then
+ tput setaf 2
+ printf "OK"
+ else
+ tput setaf 1
+ printf "Err\n"
+ tput setaf 8
+ printf "($mtmpdir/$path.log)"
+ error=true
+ fi
+ tput sgr0
+done
+
+# Show result
+printf "$reset\n\n"
+if [ "$error" = true ]; then
+ tput setaf 1
+ printf "Some part of the backup-process failed, please take a look at the logs\n"
+ tput sgr0
+ printf "Press any key to exit..."
+ read -n1
+else
+ tput setaf 2
+ printf "Backup successfull\n"
+ tput sgr0
+ printf "Exiting in 5"
+ for i in 4 3 2 1 0
+ do
+ sleep 1
+ tput cub1
+ printf "$i"
+ done
+fi
+tput cnorm
diff --git a/bin/lamp b/bin/lamp
new file mode 100755
index 0000000..36cb997
--- /dev/null
+++ b/bin/lamp
@@ -0,0 +1,15 @@
+#!/bin/bash
+ip="192.168.11.201" # Change this,
+URL="http://"$ip"/j?lamp=toggle" # Not this!
+
+HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $URL)
+HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
+HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
+
+if [ ! $HTTP_STATUS -eq 200 ]; then
+ echo -e '\033[0;31m'"Error [HTTP status: $HTTP_STATUS]"'\033[0m'
+ exit 1
+fi
+
+#echo -e "\033[0;32m $HTTP_BODY \033[0m"
+echo -e "\033[0;32mLAMP SHOULD NOW BE TOGGELED :)\033[0m"
diff --git a/bin/ping_subnet b/bin/ping_subnet
new file mode 100755
index 0000000..760d63b
--- /dev/null
+++ b/bin/ping_subnet
@@ -0,0 +1,33 @@
+#!/bin/bash
+first_ip=${1:-192.168.1.1}
+last_ip=${2:-192.168.1.254}
+
+alternate_dotted_quad_to_integer()
+{
+ IFS="." read a b c d <<< `echo $1`
+ echo "($a * 256 * 256 * 256) + ($b * 256 * 256) + ($c * 256) + $d" | bc
+}
+
+dotted_quad_to_integer()
+{
+ IFS="." read a b c d <<< `echo $1`
+ expr $(( (a<<24) + (b<<16) + (c<<8) + d))
+}
+
+integer_to_dotted_quad()
+{
+ local ip=$1
+ let a=$((ip>>24&255))
+ let b=$((ip>>16&255))
+ let c=$((ip>>8&255))
+ let d=$((ip&255))
+ echo "${a}.${b}.${c}.${d}"
+}
+
+start=$(dotted_quad_to_integer $first_ip)
+end=$(dotted_quad_to_integer $last_ip)
+for ip in `seq $start $end`
+do
+ ( ping -c1 -w1 ${ip} > /dev/null 2>&1 && integer_to_dotted_quad ${ip} ) &
+done
+wait