if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' alias wetter="curl -H 'Accept-Language: de' http://wttr.in/" alias mond="curl -H 'Accept-Language: de' http://wttr.in/Moon" fi alias ll='ls -la' alias iplu='/usr/bin/geoiplookup -f /usr/share/GeoIP/dbip4.dat' PROMPT_COMMAND='procmd' export PROMPT_COMMAND HISTSIZE=20000 HISTFILESIZE=20000 function procmd() { LaEr=$? stunde=$(date +%H) users=$(w -h|wc -l) warnus=$(whoami) freemem=$(free|grep Mem|awk '{print $4}') cpuprozs=$(acpu s0|cut -f2 -d'='|cut -f1 -d'%'|sed 's/ //g') istline=$(tput lines) istcols=$(tput cols) defcolor=$(echo "\033[0m") # Farb Definationen----------------------------------------------------------------------------------------------- normcolor=$(echo "\033[0;30;42m") #gruen minorcolor=$(echo "\033[0;30;43m") #gelb majorcolor=$(echo "\033[0;30;41m") #rot descolor=$(echo "\033[1;30;47m") #weiss # Aktivierung und Defination ------------------------------------------------------------------------------------- seite=links;feinjust="+0" checkmem=on;memgruen=120000;memgelb=100000 checklasterror=on loginusers=2 checkuseranzahl=on checkuser=on;warnuser=eUser checkcpu=on;cpugruen=5;cpugelb=10 checkdatum=on;datgruenvon=9;datgruenbis=17;dategelb1von=8;datevongelb1bis=9;datevongelb2von=17;datevongelb2bis=18 checkhostname=on checkwhoami=on checkpwd=on # Ende der Aktivierung und Defination --------------------------------------------------------------------------- if [ "$checklasterror" == "on" ] then if [ "$LaEr" == "0" ] then last=`echo -e "${normcolor}[LastError=$LaEr]${defcolor}"` else last=`echo -e "${majorcolor}[LastError=$LaEr]${defcolor}"` fi bllast=`echo "[LastError=$LaEr]"` else last="" bllast="" fi if [ "$checkuseranzahl" == "on" ] then if [ "$users" -gt "$loginusers" ] then useranz=`echo -e "${majorcolor}[User=$users]${defcolor}"` else useranz=`echo -e "${normcolor}[User=$users]${defcolor}"` fi bluseranz=`echo "[User=$users]"` else bluseranz="" useranz="" fi if [ "$checkuser" == "on" ] then if [ "${warus:0:1}" == "${warnuser:0:1}" ] then warus=`echo -e "${majorcolor}[$warnus]${defcolor}"` else warus=`echo -e "${normcolor}[$warnus]${defcolor}"` fi blwarus=`echo "$warnus"` else blwarus="" warus="" fi if [ "$checkmem" == "on" ] then if [ "$freemem" -gt "$memgruen" ] then fmem=`echo -e "${normcolor}[free=$freemem]${defcolor}"` else if [ "$freemem" -gt "$memgelb" ] then fmem=`echo -e "${minorcolor}[free=$freemem]${defcolor}"` else fmem=`echo -e "${majorcolor}[free=$freemem]${defcolor}"` fi fi blfmem=`echo "[free=$freemem]"` else blfmem="" fmem="" fi if [ "$checkcpu" == "on" ] then cpuproz=$(echo $cpuprozs|cut -f1 -d",") if $(awk 'BEGIN {return_code=('$cpuproz' >= '$cpugelb') ? 0 : 1; exit} END {exit return_code}') then cpupz=`echo -e "${majorcolor}[CPU=$cpuprozs%]${defcolor}"` fi if $(awk 'BEGIN {return_code=('$cpuproz' < '$cpugelb') ? 0 : 1; exit} END {exit return_code}')&& $(awk 'BEGIN {return_code=('$cpuproz' >= '$cpugruen') ? 0 : 1; exit} END {exit return_code}') then cpupz=`echo -e "${minorcolor}[CPU=$cpuprozs%]${defcolor}"` fi if $(awk 'BEGIN {return_code=('$cpuproz' < '$cpugruen') ? 0 : 1; exit} END {exit return_code}') then cpupz=`echo -e "${normcolor}[CPU=$cpuprozs%]${defcolor}"` fi blcpupz=`echo "[CPU=${cpuprozs}%]"` else blcpupz="" cpupz="" fi if [ "$checkdatum" == "on" ] then if [ "$stunde" -ge "$dategelb1von" ]&&[ "$stunde" -lt "$datevongelb1bis" ]||[ "$stunde" -ge "$datevongelb2von" ]&&[ "$stunde" -lt "$datevongelb2bis" ] then datum=$(echo -e "${minorcolor}[`TZ='Europe/Vienna' date`]${defcolor}") fi if [ "$stunde" -ge "$datgruenvon" ]&&[ "$stunde" -lt "$datgruenbis" ] then datum=$(echo -e "${normcolor}[`TZ='Europe/Vienna' date`]${defcolor}") fi if [ "$stunde" -lt "$datgruenvon" ]||[ "$stunde" -gt "$datgruenbis" ] then datum=$(echo -e "${majorcolor}[`TZ='Europe/Vienna' date`]${defcolor}") fi bldatum=`echo "[$(TZ='Europe/Vienna' date)]"` else bldatum="" datum="" fi if [ "$checkhostname" == "on" ] then name=$(echo -e "\033[7;36m[$(hostname)]${defcolor}") blname=`echo "[$(hostname)]"` else name="" blname="" fi if [ "$checkwhoami" == "on" ] then wer=$(echo -e "\033[7;36m[$(whoami)]${defcolor}") blwer=`echo "[$(whoami)]"` else blwer="" wer="" fi if [ "$checkpwd" == "on" ] then pfad=$(echo -e "\033[7;36m[$(pwd)]${defcolor}") blpfad=`echo "[$(pwd)]"` else blpfad="" pfad="" fi if [ "$seite" == "links" ] then llae=$(echo "${bldatum}${blname}${blfmem}${bluseranz}${blcpupz}${bllast}${blwer}${blpfad}"|wc -c) ((einr=$istcols-$llae$feinjust)) else einr=0 fi tput cup 0 $einr;echo -e "${newsrc}${datum}${name}${fmem}${useranz}${cpupz}${last}${wer}${pfad}";tput cup $istline 0 if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "${normcolor}Reinis ${FUNCNAME[0]} V1.0${defcolor}" echo -e "Zeigt ${descolor}[Datum]${defcolor}, ${descolor}[Hostname]${defcolor}, ${descolor}[freien-Speicher]${defcolor}, ${descolor}[CPU-Last]${defcolor}, ${descolor}[last-ErrorLevel]${defcolor}, ${descolor}[User@Pfad]${defcolor}, als Kopfzeile beim Terminal an." echo -e "Braucht ${descolor}PROMPT_COMMAND='${FUNCNAME[0]}'${defcolor}" echo -e "und ${descolor}export PROMPT_COMMAND${defcolor}" echo "" echo -e "Folgende Schalter sind im Functions-Code enthalten:" echo "" echo -e "${descolor}llae=${defcolor}Legt die Position fest, links oder rechts." echo -e "${descolor}feinjust=${defcolor}Feinjustierung fuer die Position." echo "" echo -e "${descolor}loginusers=${defcolor}Legt die Anzahl der aktiven User fest ab wieviel ${majorcolor}Rot${defcolor} angezeigt wird." echo "" echo -e "${descolor}checkdatum=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}, wobei folgende Werte gesetzt werden koennen" echo "Schaltet die Anzeige des Datums ein oder aus." echo -e "${descolor}datgruenvon=${normcolor}Stunde${defcolor} ab wann Uhrzeit in Gruen angezeigt werden soll." echo -e "${descolor}datgruenbis=${normcolor}Stunde${defcolor} bis wann Uhrzeit in Gruen angezeigt werden soll." echo -e "${descolor}datgelbvon=${minorcolor}Stunde${defcolor} ab wann Uhrzeit in Gelb angezeigt werden soll." echo -e "${descolor}datgelbbis=${minorcolor}Stunde${defcolor} bis wann Uhrzeit in Gelb angezeigt werden soll." echo -e "${descolor}datgelb2von=${minorcolor}Stunde${defcolor} ab wann Uhrzeit in Gelb angezeigt werden soll." echo -e "${descolor}datgelb2bis=${minorcolor}Stunde${defcolor} bis wann Uhrzeit in Gelb angezeigt werden soll." echo "Wobei Stunde ein Wert von 0..24 ist." echo -e "Zeiten ausserhalb dieser Begrentungen werden in ${majorcolor}Rot${defcolor} angezeigt." echo "" echo -e "${descolor}checkhostname=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige des Hostnamens ein oder aus." echo "" echo -e "${descolor}checkmem=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige des freien Speichers an oder aus." echo -e "${descolor}memgruen=${normcolor}Wert${defcolor} bis wohin abschwellend in Gruen angezeigt werden soll." echo -e "${descolor}memgruen=${minorcolor}Wert${defcolor} bis wohin abschwellend in Gelb angezeigt werden soll." echo "Wobei Wert in Bytes angegeben werden muss." echo -e "Werte unterhalb dieser Begrentungen werden in ${majorcolor}Rot${defcolor} angezeigt." echo "" echo -e "${descolor}checkuser=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo -e "Schaltet die Anzeige der aktiven Useranzahl an, wobei weitere aktive User ${majorcolor}Rot${defcolor} angezeigt werden." echo "" echo -e "${descolor}checkcpu=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige der CPU-Auslastung ein oder aus." echo -e "${descolor}cpugruen=${normcolor}Wert${defcolor} bis wohin aufsteigend in Gruen angezeigt werden soll." echo -e "${descolor}cpugelb=${minorcolor}Wert${defcolor} bis wohin aufsteigend in Gelb angezeigt werden soll." echo "" echo -e "${descolor}checklasterror=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige des Error-Code des letzten Befehls ein oder aus." echo -e "Error-Code welche nicht 0 entsprechen werden in ${majorcolor}Rot${defcolor} angezeigt." echo "" echo -e "${descolor}checkwhoami=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige des Usernamen ein oder aus." echo "" echo -e "${descolor}checkpwd=${normcolor}on${defcolor} oder ${majorcolor}off${defcolor}" echo "Schaltet die Anzeige der Pfadanzeige ein oder aus." echo "" echo "Im Sektor Farb Defination kann man folgende Farben einstellen." echo -e "${descolor}normcolor=${normcolor}Farbe${defcolor} die Farbe fuer normale Information." echo -e "${descolor}minorcolor=${minorcolor}Farbe${defcolor} die Farbe erste Warnung." echo -e "${descolor}majorcolor=${majorcolor}Farbe${defcolor} die Farbe hohe Warnung." echo -e "${descolor}descolor=${descolor}Farbe${defcolor} die Farbe Hinweise." return fi } function ipa () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Gibt Google Maps Link der IP-Adresse aus" return fi target="https://www.google.at/maps/place/$(/usr/bin/geoiplookup -f /usr/share/GeoIP/GeoIPCity.dat $1|cut -f2 -d':'|cut -f6-7 -d','|sed 's/,//g'|cut -f2- -d' ')" echo "$target" } function such () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "${FUNCNAME[0]} Suchbegriff1 Suchbegriff2 Suchbegriff3 Suchbegriff4 Datei" echo -e "Liefert \033[0;31mSuchmuster1 \033[1;34mSuchmuster2 \033[0;32mSuchmuster3 \033[1;33mSuchmuster4" echo -e "\033[0;31mJoker wie \* muessen mit \\ entwertet werden!\033[0m" return fi if [ "$#" -lt 2 ]; then echo "such Suchbegriff1 Suchbegriff2 Suchbegriff3 Suchbegriff4 Datei" elif [ "$#" -eq 2 ]; then cat $2|GREP_COLORS="mt=01;31" zgrep --color=always "$1" elif [ "$#" -eq 3 ]; then cat $3|GREP_COLORS="mt=01;31" zgrep --color=always "$1" | GREP_COLORS="mt=01;34" zgrep --color=always "$2" elif [ "$#" -eq 4 ]; then cat $4|GREP_COLORS="mt=01;31" zgrep --color=always "$1" | GREP_COLORS="mt=01;34" zgrep --color=always "$2" | GREP_COLORS="mt=01;32" zgrep --color=always "$3" elif [ "$#" -eq 5 ]; then cat $5|GREP_COLORS="mt=01;31" zgrep --color=always "$1" | GREP_COLORS="mt=01;34" zgrep --color=always "$2" | GREP_COLORS="mt=01;32" zgrep --color=always "$3" | GREP_COLORS="mt=01;33" zgrep --color=always "$4" fi } function vsuch () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Durchsucht nach Suchbegriff Verzeichniss mit Tiefe NR" echo "EXAMPLE:" echo "${FUNCNAME[0]} Suchbegriff /Verzeichnis" return fi if [ "$#" -lt 2 ]; then echo "vsuch Suchbegriff Verzeichniss Tiefe (default=0)" else if [ -z "$3" ]; then depth=0 else depth="$3" fi echo "----------File:StringNR:Hit-------------" grep -n "$1" $(find "$2"/* -maxdepth $depth) 2>/dev/null fi } function encrypt () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Verschluesselt File Fuer User" return fi gpg --cipher-algo AES256 --symmetric "$1"&&rm "$1" } function decrypt () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Entschluesselt File Fuer User" return fi gpg --output "$1" --decrypt ${1}.gpg&&rm "$1.gpg" } function pass() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Erzeugt sichere Passwoerter" return fi if [ "$#" -ne 1 ]; then count=15 else count="$1" fi pass=`&2>/dev/null&&echo -e "\033[1;31m$a\033[0m";echo $a|grep -v ttp: 1>&2>/dev/null&&echo $a;done } function headers() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Zeigt Header, welcher Webserver" return fi curl -k -I https://"$1"/ } function allowip() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Erlaubt IP" return fi sudo iptables -I INPUT -s "$1" -j ACCEPT sudo iptables -A OUTPUT -d "$1" -j ACCEPT } function bytestohuman() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Wandelt Bytes in leserliche Groesse um" return fi b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,P,E,Z,Y,B}iB) while ((b > 1024)) do d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))" b=$((b / 1024)) let s++ done echo "$b$d ${S[$s]}" } function dub() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo -e "\033[0;32m${FUNCNAME[0]} listet SIZE und sortiert\033[0m" echo "${FUNCNAME[0]} -d listet keine Unterverzeichnisse" echo "-dNR:" echo "NR = Verzeichnisstiefe" echo "EXAMPLE:" echo "${FUNCNAME[0]} -d3 /var/log" echo "Listet Size sortiert in Tiefe von 3 Verzeichnissen auf" return fi if [ "${1:0:2}" == "-d" ] then if [ "${1:2:2}" == "" ] then deep=1 else deep=$(echo "${1:2:2}") fi CMD="du -b --max-depth=$deep $2" else CMD="du -b $1" fi $CMD|sort -n|while read SIZELINE do SIZE=$(echo $SIZELINE|cut -f1 -d" ") LINE=$(echo $SIZELINE|cut -f2- -d" ") echo "$(bytestohuman $SIZE) $LINE"|sed 's/\.\// /g' done } function demo () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Zeigt eine kleine Demo" return fi istcols=$(tput cols) clear ((istcols=istcols-120)) for a in 11 12 13 14 15 16 17 18 19 20 do altnum=$(head -n2 ~/.bash-tools/demo$a|cut -f2 -d'['|cut -f1 -d'G'|tail -n1) sed -i "s/${altnum}G/${istcols}G/g" ~/.bash-tools/demo$a done for a in 11 12 13 14 15 16 17 18 19 20 do tput cup 1;cat ~/.bash-tools/demo$a done } function bhelp() { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Listet Reinis .bashrc Tools" return fi istcols=$(tput cols) clear ((istcols=istcols-106)) altnum=$(head -n2 ~/.bash-tools/bash-tools|cut -f2 -d'['|cut -f1 -d'G'|tail -n1) sed -i "s/${altnum}G/${istcols}G/g" ~/.bash-tools/bash-tools cat ~/.bash-tools/bash-tools echo "" echo "" tput cup 1;grep ^function $HOME/.bashrc|cut -f2 -d" "|cut -f1 -d'(' echo "" echo "use -? or -h or -help for help" } function sc() { unset anum if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]}\033[0m" echo "Oeffnet Screen-Sitzungen" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} -l\033[0m" echo "Listed die vorhandenen Screen-Sitzungen" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} -r\033[0m" echo "Reconnectet vorhandene Screen-Sitzungen" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} -d\033[0m" echo "Loescht die vorhandenen Screen-Sitzungen" return fi if [ "$1" == "-l" ] then screen -ls|grep 'Detached'|cut -f2 -d'-'|awk {'print $1'}|sort -n 2>/dev/null return fi if [ "${1:0:2}" == "-d" ] then if [ "${#1}" -le "2" ] then delnr=0 while [ "$delnr" != "q" ] do screen -ls|grep 'Detached'|cut -f2 -d'-'|awk {'print $1'}|sort -n 2>/dev/null read -p "Nr des zu loeschenden Screens oder \"q\" fuer quit:" delnr if [ "$delnr" == "q" ] then return fi delstr=$(screen -ls|awk {'print $1'}|grep "\-$delnr") screen -S "$delstr" -X quit 2>&1>/dev/null if [ "$delnr" != "" ] then echo "Screen $delnr beendet" else echo "Kein Screen zum beenden vorhanden." fi done fi return fi if [ "${1:0:2}" == "-r" ] then if [ "${#1}" -le "2" ] then delnr=0 while [ "$delnr" != "q" ] do screen -ls|grep 'Detached'|cut -f2 -d'-'|awk {'print $1'}|sort -n 2>/dev/null read -p "Nr des zu reconnet Screens oder \"q\" fuer quit:" delnr if [ "$delnr" == "q" ] then return fi delstr=$(screen -ls|awk {'print $1'}|grep "\-$delnr") screen -r "$delstr" done fi return fi unset snum for a in $(screen -ls|grep 'Detached'|cut -f2 -d'-'|awk {'print $1'}|sort -n) do snum="$snum $a-," done if [ "$snum" == "" ] then screen -S Screen-1 return fi while : do ((anum=anum+1)) echo "$snum"|grep -v " $anum-" 1>&2>/dev/null&&screen -S Screen-$anum&&return done screen -S Screen-1 } function cls () { unset anum if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo "Reinis clear Screen Gimmick" return fi clear istline=$(tput lines) istcols=$(tput cols) dunkel="\e[48;5;$(shuf -i 4-231 -n 1)m" hell="\e[48;5;$(shuf -i 4-231 -n 1)m" norm="\e[0m" ((down=3)) ((pos=$istcols-30)) tput cup $down $pos; echo -en " $hell $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $dunkel $dunkel $hell $norm $dunkel $hell $norm";echo ;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $dunkel $hell $norm $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $norm $hell $dunkel $hell $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $norm $hell $dunkel $norm";echo;((down=down+1)) tput cup $down $pos; echo -en " $hell $dunkel $hell $norm";echo; tput cup $istline 0 } function iowa () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} IP-Adresse CPU_NR\033[0m" echo "Zeigt IOWAIT von CPU_NR der IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" echo "CPU_NR default ist Durchschnitt aller CPUs" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") cpunr=$(echo "$2") else remote=$(echo "") cpunr=$(echo "$1") fi if [ "$cpunr" == "" ] then cpunr=$(echo "1") else ((cpunr=cpunr+1)) fi rstat=$($remote head -n$cpunr /proc/stat|tail -n1|awk '{$1=""; print $0}') b=0 for a in $rstat do ((b=b+$a)) done c=$(echo "$rstat"|awk '{print $5}') iowait=$(echo|mawk '{OFMT="%.2f";print '$c'*100/'$b'}') if [ "$remote" == "" ] then remote=$(echo "localhost") fi if [ "$cpunr" == "1" ] then cpun=$(echo "Last-Durchschnitt") else ((cpunr=cpunr-1)) cpun=$(echo "CPU_NR $cpunr") fi echo "IOWAIT $cpun von $remote = $iowait" } function idl () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} IP-Adresse CPU_NR\033[0m" echo "Zeigt IDLE-Zeit von CPU_NR der IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" echo "CPU_NR default ist Durchschnitt aller CPUs" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") cpunr=$(echo "$2") else remote=$(echo "") cpunr=$(echo "$1") fi if [ "$cpunr" == "" ] then cpunr=$(echo "1") else ((cpunr=cpunr+1)) fi rstat=$($remote head -n$cpunr /proc/stat|tail -n1|awk '{$1=""; print $0}') b=0 for a in $rstat do ((b=b+$a)) done c=$(echo "$rstat"|awk '{print $4}') iowait=$(echo|mawk '{OFMT="%.2f";print '$c'*100/'$b'}') if [ "$remote" == "" ] then remote=$(echo "localhost") fi if [ "$cpunr" == "1" ] then cpun=$(echo "Last-Durchschnitt") else ((cpunr=cpunr-1)) cpun=$(echo "CPU_NR $cpunr") fi echo "IDLE-Time $cpun von $remote = $iowait" } function acpu () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} IP-Adresse CPU_NR\033[0m" echo "Zeigt CPU-Auslastung von CPU_NR der IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" echo "CPU_NR default ist Durchschnitt aller CPUs" echo "" echo "Default timing = s3, also 3 Sekunden" echo "" echo "Exapmle:" echo -e "\033[1;30;47m${FUNCNAME[0]} 192.168.0.10 4 s5\033[0m" echo "Misst von IP 192.168.0.10 der 4tn CPU alle 5Sekunden" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") cpunr=$(echo "$2") else remote=$(echo "") cpunr=$(echo "$1") fi if [ "$cpunr" == "" ] then cpunr=$(echo "1") else ((cpunr=cpunr+1)) fi timese=$(for x in $*;do echo $x|grep '^s';done) timeset=$(echo ${timese:1:2}) if [ "$timeset" == "" ] then timeset=$(echo "3") fi if [ "$remote" == "" ] then remot=$(echo "localhost") else remot=$(echo "$remote") fi if [ "$cpunr" == "1" ] then cpun=$(echo "Last-Durchschnitt") else ((cpunr=cpunr-1)) cpun=$(echo "CPU_NR $cpunr") fi while : do cpu_now=($($remote head -n$cpunr /proc/stat|tail -n1)) cpu_sum="${cpu_now[@]:1}" cpu_sum=$((${cpu_sum// /+})) cpu_delta=$((cpu_sum - cpu_last_sum)) cpu_idle=$((cpu_now[4]- cpu_last[4])) cpu_used=$((cpu_delta - cpu_idle)) cpu_usage=$(echo|mawk '{OFMT="%.2f";print 100 * '$cpu_used'/'$cpu_delta'}') cpu_last=("${cpu_now[@]}") cpu_last_sum=$cpu_sum echo "Auslastung $cpun von $remot = $cpu_usage%" sleep $timeset if [ $timeset == 0 ] then return fi done } function cpunrs () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo "Zeigt die Anzahl der CPUs von IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") cpunr=$(echo "$2") else remote=$(echo "") cpunr=$(echo "$1") fi if [ "$remote" == "" ] then remot=$(echo "localhost") else remot=$(echo "$remote") fi $remote cat /proc/stat|grep '^cpu'|awk '{print $1}' } function hddl () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo "Zeigt den Speicherplatz der HDDs von IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") else remote=$(echo "") fi if [ "$remote" == "" ] then remot=$(echo "localhost") else remot=$(echo "$remote") fi $remote cat /proc/partitions|grep -v major|grep "\S"|while read a do echo $(echo $a|awk '{print $4}';bytestohuman $(echo $a|awk '{OFMT="%.0f";print $3 *1024}')) done } function anonym () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo $1 echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "${FUNCNAME[0]} /Pfad/Datei" echo -e "Anonymisiert gueltige IP-Adressen und" echo -e "E-Mail-Adressen." echo -e "Liefert XXX.XXX.XXX.XXX fuer IP-Adressen aus und" echo -e "Liefert xxx@xxx.TLD fuer E-Mail-Adressen aus." return fi if [ "$1" == "" ] then cat -|zless|sed -r 's/([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})/® &/g'|sed -r 's/ (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/ XXX.XXX.XXX.XXX/g'|sed -r 's/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\-(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\-(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\-(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/XXX-XXX-XXX-XXX/g'|sed -r 's/