Archive for category Bash-Oneliner

New Year, New Oneliner

So fangen wir mal an, ich mußte gerade kurz einpaar dateien aus 2 Verzeichnissen abgleichen mein erster Einfall war das hier:

root@server:/usr/local/nagios-x64/libexec# for i in *; do [[ -f ../../nagios/libexec/$i ]] || echo "$i not available"; done
check_http_status not available
check_md not available
check_memory not available
check_smart not available
root@server:/usr/local/nagios-x64/libexec#

Ist eigentlich ganz geschmeidig :) man könnte es natürlich auch mit rsync –dry-run machen oder 2 Textfiles und diff, die Möglichkeiten sind unendlich ;)

December Oneliner

Want to make all files in your current directory lower case?

for i in * ; do mv $i $(echo $i | tr [A-Z] [a-z]); done

Want to sum the size of all directorys in one folder?

for i in * ; do if [ -d $i ]; then du -sh $i; fi; done

or shorter

for i in * ; do [[ -d $i ]] && du -sh $i; done

Want the Top10 Referer of your Website?

gzip -cd access_log.*.gz |  awk '{print $11}' | grep -v "\"-\"" | sort | uniq -c | sort -nr | head

Want to adjust an IP in all of your Apache virtual host files?

for i in *; do sed -e "s/80.3/81.3/" $i > $i.new; mv $i.new $i; done

Want to know the speed while filling a directory?

b=$(du -sm|awk '{print $1}'); sleep 60; e=$(du -sm|awk '{print $1}'); echo "$b $e" | awk '{ printf("%4.2fMB/s\n", ($2-$1)/60 )}'

Want to know if there are any critical/sercurity updates available for your Debian/Ubuntu?

apt-get -s upgrade | grep "^Inst" | egrep -i "(Debian-Security:|Ubuntu:[^/]*/[^-]*-security)" | wc -l | awk '{print "Critical Updates:", $1}'

Bash Oneliner

Ich habe mir gedacht fasse ich mal alle Bash Oneliner des Monats zusammen :) die ich so im Tagesgeschäft finde