Monday, December 13, 2010

Prevent Accident Shutdown/Reboot

In order to prevent root or super users accidentally shutdown or reboot the Linux server, you can apply the follow method:
  1. Login to root, and edit /etc/profile with vi
  2. Add the following to the end of file /etc/profile
safereboot () {
      echo -e "\033[32;1m\ \      / / \  |  _ \| \ | |_ _| \ | |/ ___| |\033[0m"
      echo -e "\033[32;1m \ \ /\ / / _ \ | |_) |  \| || ||  \| | |  _| |\033[0m"
      echo -e "\033[32;1m  \ V  V / ___ \|  _ <| |\  || || |\  | |_| |_|\033[0m"
      echo -e "\033[32;1m   \_/\_/_/   \_\_| \_\_| \_|___|_| \_|\____(_)\033[0m"
      echo -e "Are you sure you wanna \033[31;1mSHUTDOWN\033[0m? (Type HOSTNAME to confirm)"
      read confirm
      if [ "$HOSTNAME" == "$confirm" ]; then
              sudo /sbin/shutdown -r +1
      else
              echo "SHUTDOWN aborted..."
      fi
  }
  alias reboot='safereboot'
  alias shutdown='safereboot'
  alias poweroff='safereboot'
 
 
 
eight basic EGA colors are defined as follows: 

30    black foreground
31    red foreground
32    green foreground
33    brown foreground
34    blue foreground
35    magenta (purple) foreground
36    cyan (light blue) foreground
37    gray foreground
 

No comments:

Post a Comment