bash
Bourne again shell.
Server loop
1
2
3 logger "Starting server.py"
4 until /usr/bin/python server.py 1234; do
5 logger "Server crashed with exit code $?. Respawning.."
6 sleep 1
7 done
Adapted from http://unclean.org/howto/secondip.html
Add extra IP 192.168.1.5 to NIC eth0
1 ifconfig eth0:0 192.168.1.5
2 route add -host 192.168.1.5 dev eth0:0
Check port running
1
2 RES=`netstat -at -n | grep 0.0.0.0:12345 | wc -l`
3 if [ $RES -eq '1' ]
4 then
5 logger 'Process running'
6 else
7 logger 'Process not listening on port 12345'
8 /sbin/service processx restart
9 logger 'Process restarted'
10 fi
1
2 RES=`netstat -at -n | grep 0.0.0.0:12345 | wc -l`
3 if [ $RES -ne '1' ]
4 then
5 logger 'Process not listening on port 12345'
6 /sbin/service processx restart
7 logger 'Process restarted'
8 fi
ColorBash prompt
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
- start coloring: \[\e[color\]
- end coloring: \[\e[m\]
- \e[0;32m\] #green color
- \e[0;33m\] #yellow color
Network interface data daily
rxtxData.sh:
1
2
3
4
5 CURR=`date -u`
6 DATA=`ifconfig eth0 | grep "RX bytes" | sed "s/:/ /g"`
7 echo [$CURR] $DATA >> /root/rxtxData.log
SSH Ubuntu bash colors
~/.bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
~/.bashrc
alias ls='ls --color'
PS1="\e[0;33m\]\D{%Y-%m-%d}T\A\[\e[m\] \e[0;32m\]\u@\H:\w\r\n\$\[\e[m\] "