Search Posts on Binpipe Blog

Disabling Ctrl+Alt+Delete Reboot Shortcut in Linux Systems

Pressing CTRL+ALT+DELETE on most Linux distributions will start the soft reboot process. On production systems, it is advisable to disable this because someone might make a mistake and reboot the system, specially those who are used to administrate Windows servers. Also what is strange about this shortcut is that you don’t need to be logged in (no user/password needed – but only console access) to reboot the system.

To disable this behavior, open the /etc/init/control-alt-delete.conf configuration file in a text editor such as vi, nano or pico. (The same settings are present in /etc/inittab in RHEL/CentOS 5 systems)
Then replace the actual shutdown action with an alert:

# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.

start on control-alt-delete

#exec /sbin/shutdown -r now "Control-Alt-Delete pressed"
exec echo "CONTROL-ALT-DELETE DISABLED BY ADMIN"

The init daemon should automatically reload this change, but just to be sure run this command:

initctl reload-configuration

Code Snippet: To find the number of hits per domain in a Shared Server (CPanel on Linux)

You can run the following command line recipe to find the number of hits per domain in a Shared Server (CPanel on Linux):

 a=$(date +%s); touch /root/$a; for domains in `cat /etc/userdomains | cut -d : -f 1`; do wc -l /etc/httpd/domlogs/$domains >> /root/$a 2>/dev/null; done; cat /root/$a | grep -v "0 /etc/" | sort -nk1 | tail -6 >> /root/test.txt; rm -rf /root/$a; for ((c=1; c<=6; c++)); do awk "NR==$c{print;exit}" /root/test.txt | awk {'print $2'} | xargs head -n1 | cut -d= -f1 | sed '/^$/d' | awk {'printf "Since " $4 "] there were "'}; awk "NR==$c{print;exit}" /root/test.txt | awk {'printf $1 " hits to "'}; awk "NR==$c{print;exit}" /root/test.txt | awk -F/ {'print "["$5"]"'}; done; rm -f /root/test.txt;


The output will something be like this:

Since [18/Jun/2013:13:06:25] there were 5163 hits to [test.com]
Since [18/Jun/2013:13:04:46] there were 7402 hits to [test1.com]
Since [18/Jun/2013:13:06:43] there were 8586 hits to [test2.com]
Since [18/Jun/2013:13:04:58] there were 9808 hits to [test3.info]
Since [18/Jun/2013:13:04:57] there were 15218 hits to [test4.com]
Since [18/Jun/2013:13:04:51] there were 26965 hits to [test5.com]

Code Snippet: User wise Memory Consumption in a CPanel based Linux Server


Run the following command snippet to output a neatly formatted User wise Memory Consumption in a CPanel based Linux Server :

OUT=$(/usr/local/cpanel/bin/dcpumonview | grep -v Top | sed -e 's#<[^>]*># #g' | while read i ; do NF=`echo $i | awk {'print NF'}` ; if [[ "$NF" == "5" ]] ; then USER=`echo $i | awk {'print $1'}`; OWNER=`grep -e "^OWNER=" /var/cpanel/users/$USER | cut -d= -f2` ; echo "$OWNER $i"; fi ; done) ; (echo "USER CPU" ; echo "$OUT" | sort -nrk4 | awk '{printf "%s %s%\n",$2,$4}' | head -5) | column -t ; echo; (echo -e "USER MEMORY" ; echo "$OUT" | sort -nrk5 | awk '{printf "%s %s%\n",$2,$5}' | head -5) | column -t