Tuesday, April 14, 2009

Disable the Ctrl-Alt-Delete shutdown keys

For people who have recently migrated from MS boxes to Nix ones have a habit of using Ctrl+Alt+Del keys for popping up Task Manager or to simply lock the workstation but using that combination on Linux box is hazardous as it shuts down the machine.

So I recommend on disabling Ctrl+Alt+Del keys on your workstation, even on production systems it is recommended that you disable it

It is configured using /etc/inittab (used by sysv-compatible init process) file. The inittab file describes which processes are started at bootup and during normal operation. You need to open this file and remove (or comment it) ctrlaltdel entry.

Ctrlaltdel specifies the process that will be executed when init receives the SIGINT signal. SIGINT is the symbolic name for the signal thrown by computer programs when a user wishes to interrupt the process, for example reboot/shutdown system using [Ctrl]-[Alt]-[Del].). This means that someone on the system console has pressed the CTRL-ALT-DEL key combination. Typically one wants to execute some sort of shutdown either to get into single-user level or to reboot the machine.

How-To disable Ctrl+Alt+Del Keys:

Open /etc/inittab file, enter:
# vi /etc/inittab

Search for line that read as follows:
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

And remove the line or comment out the above line by putting a hash mark (#) in front of it:
# ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now

Save the file and exit to shell promot. Reboot system to take effect or type command:
# init q

Trim 1.0 - Removes a number of lines from the beginning of a file

Good utility for people who are not much into scripting.

Excerpts form MANUAL:

Utility used to monitor and control the sizes of (log) files. Examines a text file to see if its length has exceeded a certain limit; if it has, Trim removes a certain number of lines from the beginning of the file. Ideal for use in crontab.


Download source - trim-1.0.tar.gz [4 kb]

Secret Maryo Chronicles 1.8


The Super Mario-inspired platforming game Secret Maryo Chronicles is now at version 1.8 with improved moving platforms and updated sprites.


Screenshots: [ View ] Download: [ secretmaryo.org ]

Tuesday, April 7, 2009

Find and calculate total size of files older than a month

For some applications it is very common to create temporary files or we can say cache files periodically, which if not removed regularly can consume a lot of disk space unnecessarily. Here is a tip which will save you from wondering how to find and get rid of these.

1. Here's a simple script to find and calculate total size of the files found if you just want to know if these exist under your application or not:

#!/bin/bash

export CACHE_DIR=/path/to/Cache/dir
export file_list=/var/log/cachecron/CacheCron.log.`date +"%Y%m%d_%H%M"` ;
export cache_report=/var/log/cachecron/CacheReport.log.`date +"%Y%m%d_%H%M"` ;
export size=0

#### List cache files #########

find $CACHE_DIR -type f -mtime +30 -exec ls -lAh {} \;| awk '{print $9}' > $file_list ;

##### Calculating the size of cache ##########

echo "CACHE Watch for SEVERNAME `date +"%d-%m-%Y"`" > $cache_report;
echo " " >> $cache_report;
echo "List of files is kept at $file_list" >> $cache_report;
echo "Total no. of files found `cat $file_list|wc -l`" >> $cache_report;
for file in `cat ${file_list}`; do
if [ -f "${file}" ]; then
file_size=`ls -l ${file} | awk '{print $5}'`
size=`expr ${size} + ${file_size}`
fi
done
echo " " >> $cache_report;

### Display Consolidated size in MB###########

echo "Overall Cache: $((${size} / 1048576)) MB" >> $cache_report;

#####Overnight mailer for daily log watch#####

mailx -s "CACHE Watch for SERVERNAME `date +"%d-%m-%Y"`" nixtrap@blogspot.com < $cache_report; #####################################


2. That was just to keep a check on log files and track on daily addition of cache files with respect to nuber and size. If this all seems crap to you and you just want to get rid of these without any intimation here's a one liner for you:

$ find /Cache/dir/path -type f -mtime +30 -exec rm -f {} \;

poof !! there goes the crap ... but before running that just make sure what you are going to erase. This one liner will only list the files found:

$ find /Cache/dir/path -type f -mtime +30 -exec ls -la {} \;