Skip to content

Instantly share code, notes, and snippets.

@richardsonlima
Last active March 21, 2018 11:43
Show Gist options
  • Save richardsonlima/2d99a7d1899f3055362c to your computer and use it in GitHub Desktop.
Save richardsonlima/2d99a7d1899f3055362c to your computer and use it in GitHub Desktop.
# Find Linux accounts locked
sudo cat /etc/passwd | cut -d : -f 1 | awk '{ system("passwd -S " $0) }'|grep --color -iE 'Password locked'
# real-time countdown timer
while true; do echo -ne "`date +%H:%M:%S:%N`\r"; done
du --block-size=MiB --max-depth=1 | sort -n
# total percentage of memory use for all processes with a given name
ps -eo pmem,comm | grep java | awk '{sum+=$1} END {print sum " % of RAM"}'
ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
# Test remote SSH server status using telnet (no login required)
$if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then <command when up>; else <command when down>; fi;
if [[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]]; then echo 1; else echo 0; fi
[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] && <command when up>
[[ "$(sleep 1 | telnet -c <host> <port> 2>&1 | grep '^SSH')" == SSH* ]] || <command when down>
# check open ports without netstat or lsof
declare -a array=($(tail -n +2 /proc/net/tcp | cut -d":" -f"3"|cut -d" " -f"1")) && for port in ${array[@]}; do echo $((0x$port)); done
# Powershell Ping Logs Host Up/Down Events
# IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type
sajb {$ip="192.168.100.1";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}
# check remote port without telnet
cat < /dev/tcp/74.125.224.40/80
: </dev/tcp/127.0.0.1/80
(: </dev/tcp/127.0.0.1/80) &>/dev/null && echo "OPEN" || echo "CLOSED"
# Auto log commands
alias m='screen -S $$ -m script'
# DU colored
du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment