MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Unknown action login.
  • bash

Contents

  1. bash
    1. Server loop
    2. Add extra IP address to NIC
    3. Check port running
    4. ColorBash prompt
    5. Network interface data daily
    6. SSH Ubuntu bash colors

bash

Bourne again shell.

Server loop

   1 #!/bin/sh
   2 # restart the server in case of failure
   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

Add extra IP address to NIC

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 #!/bin/sh
   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 #!/bin/sh
   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 #!/bin/sh
   2 # chmod 755 rxtxData.sh
   3 # crontab -e
   4 # @daily /root/rxtxData.sh
   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'
alias ps='ps faxo pid,user:32,comm'
#PS1="\e[0;33m\]\D{%Y-%m-%d}T\A\[\e[m\] \e[0;32m\]\u@\H:\w\r\n\$\[\e[m\] "
export PS1="\e[0;33m\]\D{%Y-%m-%d}T\A\[\e[m\] \e[0;32m\]\u@\H:\w\r\n\$\[\e[m\] "
PATH=$PATH:/opt/java/jdk1.8.0_162/bin:/opt/java/apache-maven-3.5.3/bin
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01