Skip to content

Instantly share code, notes, and snippets.

@proycon
Forked from naiaden/ca
Last active August 19, 2019 22:27
Show Gist options
  • Select an option

  • Save proycon/62e99cc9c3e4f4e1bc8a to your computer and use it in GitHub Desktop.

Select an option

Save proycon/62e99cc9c3e4f4e1bc8a to your computer and use it in GitHub Desktop.
info over ssh scripts
#!/bin/bash
green='\033[1;92m'
yellow='\033[1;93m'
red='\033[1;91m'
blue='\033[1;31m' #"\033[1;96m"
normal='\033[0m'
if [ -z "$PONY" ]; then
if [ -f /etc/profile.d/mlp.sh ]; then
source /etc/profile.d/mlp.sh
fi
fi
comp=$PONY/`hostname`
cores=`lscpu | grep '^CPU(s):' | awk '{print $2}' | tr -d ' '`
memtotal=`free -g | grep Mem | awk '{print $2}'`
memfree=`free -g | grep Mem | awk '{sum+=$4+$7} END {print sum}'`
swap=`free -g | grep Swap | awk '{print $3}'`
#longload=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,/./' | awk '{FS=", "}{print $3}')
longload=$(uptime | awk -F'[a-z]:' '{ print $2}' | awk '{FS=", "}{print $3}' | sed 's/,/./')
if [ $# -eq 0 ] || [ $1 -le $memfree ]; then
### SERVER CAPABILITIES + LOAD ###
#w |& gawk -v comp=$comp '/average/ {days=match($0,"day")?$3:"0"; printf("%12s : up %3s days | load %6s %6s %5s",comp,days,$(NF-2),$(NF-1),$NF)}'
# if [ "$longload" -gt 24 ]; then
# color=$red
## elif [ "$longload" -gt "8" ]; then
## color=$yellow
# else
# color=$green
# fi
color=$green
if [ "${memtotal}" -lt "120" ]; then
color=$red
elif [ "${memtotal}" -lt "240" ]; then
color=$yellow
else
color=$green
fi
printf "%b%20s (%2s CPUs, %3s GB)%b:" "$color" "$comp" "$cores" "$memtotal" "$normal"
color=$green
if [ "${longload%%.*}" -lt "9" ]; then
color=$green
elif [ "${longload%%.*}" -lt "25" ]; then
color=$yellow
else
color=$red
fi
w |& gawk -v normal=$normal -v color=$color '/average/ {printf("%s%7s %7s %6s%s",color,$(NF-2),$(NF-1),$NF,normal)}'
echo " | " | perl -ne 'chomp; print "$_ ";'
### FREE MEMORY (includes cached mem) ###
#cat /proc/meminfo | head -n 2 | perl -ne 'chomp; print "$_ ";' ; echo " | " | perl -ne 'chomp; print "$_ ";'
if [ "$memfree" -gt "200" ]; then
color=$green
elif [ "$memfree" -gt "100" ]; then
color=$yellow
else
color=$red
fi
printf "$color %3s GB MEM %s $normal| " $memfree
if [ "$swap" -gt "100" ]; then
color=$red
elif [ "$swap" -gt "50" ]; then
color=$yellow
else
color=$green
fi
printf "$color %3s GB SWAP %s $normal| " $swap
### ACTIVE USERS ###
usrs=$(ps aux | awk '{if($3 > 1.0) { print $1}}' | sort | uniq -c | sort -nr)
usrs1=$(echo "$usrs" | head -n 4 | sed -e 's/^[ \t]*//' | awk '{print $2 "(" $1 ")"}' | paste -sd " ")
# echo -n "${usrs1}"
while read -r line; do
loutp=$(echo "$line" | awk '{print $2 "(" $1 ")"}')
# echo $loutp;
#loutp="asd"
if [[ $loutp == *"$USER"* ]]
then
printf " $blue$loutp$normal";
else
printf " $normal$loutp$normal";
fi
done <<< "${usrs}"
# #w -h | grep -v "sh" | cut -c1-8 | sort| uniq | perl -ne 'chomp; print "$_ ";'
# top -b -n 1 |\
# tail -n +8 |\
# sort -k 2 |\
# sed '$a\1 2 3 4 5 6 7 8 9 10 11 12' |\
# awk '{\
# if ($9 > 0 && $12 != "top") {\
# if ($2 == prev || prev == "")\
# sum+=1;\
# else {\
# if (prev != "root"){\
# printf("%8s %2s\n",prev,sum);\
# }\
# sum=1;\
# };\
# prev=$2\
# }\
# }' | sort -n -r -k 2 | perl -ne 'chomp; $line=$_; if($line =~ /^ lonrust/) {print "\e[1;96m$line\e[0m ";} else {print "$line ";}'
echo ''
fi
#!/bin/bash
comp=`hostname`
echo $comp
echo -en '\e[32m'
find /scratch/$USER -newermt "$1"
echo -en '\e[39m'
#!/bin/bash
comp=`hostname`
echo $comp
echo -en '\e[32m'
find /scratch/$USER -name "$1"
echo -en '\e[39m'
#!/bin/bash
RED='\033[1;31m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
PONIES=12
for i in $(seq 1 $PONIES); do
if [ $i -lt 10 ]; then
comp="mlp0$i"
else
comp="mlp$i"
fi
echo -e "${BLUE}=================${WHITE} $comp ${BLUE}=================${NC}"
if [[ $comp != %* ]]; then
ssh $comp $@
fi
done
#!/bin/bash
echo "in home"
find ~ -newermt "$1"
echo "tensusers"
find /vol/tensusers/$USER -newermt "$1"
for comp in `cat $HOME/bin/ponies`; do
if [[ $comp != %* ]]; then
ssh $comp $HOME/bin/lfchange $1
fi
done
#!/bin/bash
echo "in home"
find ~ -name "$1"
echo "tensusers"
find /vol/tensusers/$USER -name "$1"
parallel -j 100 --onall --slf /vol/customopt/lamachine2/src/ca/ponies lfind ::: $1
for comp in `cat $HOME/bin/ponies`; do
if [[ $comp != %* ]]; then
ssh $comp $HOME/bin/lfind $1
fi
done
#!/bin/bash
PONIES=12
for i in $(seq 1 $PONIES); do
if [ $i -lt 10 ]; then
comp="mlp0$i"
else
comp="mlp$i"
fi
if [[ $comp != %* ]]; then
ssh $comp /vol/customopt/ca/ca $1
fi
done
applejack
rarity
fancypants
fluttershy
pipsqueak
scootaloo
cheerilee
blossomforth
featherweight
twist
thunderlane
#!/bin/bash
for comp in `cat /home/lonrust/local/bin/ponies`; do
if [[ $comp != %* ]]; then
ssh $comp ~lonrust/local/bin/runpro
fi
done
#!/bin/bash
RED='\033[1;31m'
BLUE='\033[1;34m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
PONIES=12
for i in $(seq 1 $PONIES); do
if [ $i -lt 10 ]; then
comp="mlp0$i"
else
comp="mlp$i"
fi
echo -e "${BLUE}=================${WHITE} $comp ${BLUE}=================${NC}"
if [[ $comp != %* ]]; then
setvars=""
if [ ! -z "$TMPDIR" ]; then
setvars="export TMPDIR=$TMPDIR; "
fi
ssh $comp $setvars/vol/customopt/ca/tls $1
fi
done
#!/bin/bash
echo -en '\e[96m'
echo $(hostname)
echo -en '\e[39m'
ps -u lonrust -o "%C,%z,%a" | awk '{FS=","}{if(NR>1){
cmd = "numfmt --to=iec --from-unit=1024 " $2
while (cmd | getline line) {
if($1 > "1.0" && $3 !~ /^stress/) {print ($1>85.0 ? "\033[1;92m" : "\033[1;91m"), $1, line, $3, "\033[0m "}
}
close(cmd)
}}'
#!/bin/bash
comp=`hostname`
mem=`free | awk 'FNR == 3 {print $4/($3+$4)*100}'`
ps haux | awk -v user=$USER -v comp=$comp -v mem=$mem '$1 ~ user { sum += $4} END { print comp " using:", sum " free:" mem; }'
tmux list-windows 2>/dev/null | while read line; do if [[ $line =~ "(active)" ]]; then clr='\e[0;32m'; else clr='\e[0;37m'; fi; echo -e $clr " " "$line"; done
echo -en '\e[0m'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment