Archive for the ‘Shell tips’ Category

I use the following periodically to see if i have some big files on my /var/log/ directory

# find all big files over 1 MB in /var/log and sort them with size
find /var/log -type f -size +1M -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nk 2,2

and to move all gzipped files from /var/log/ to /var/backuplog/ and make some clean space

find /var/log -iname '*.gz' -exec mv '{}' /var/backuplog/ \

This is a collection of commands i found on the net and wrote them on a executable file to monitor connections on my server

echo "List count of number of connections the IPs are connected to the server using TCP or UDP protocol."
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n ;

echo "How many active SYNC_REC are happening on the server.Less than 5 is OK."
netstat -n -p|grep SYN_REC | wc -l

echo "List out the all IP addresses involved."
netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'

echo "List out the all connections to port 80."
netstat -n -a -p|grep :80

echo "Which ip's are having more connection to 80 port."
netstat -anp | grep :80 | awk '{print $5}' | sort | uniq -c | sort -n

Optimize roundcube

Posted: 04/04/2013 in Shell tips
Tags: ,

Use this to optimize roundcube load time. Just edit:

vim /var/lib/roundcube/config/

And make these changes

// Type of IMAP indexes cache. Supported values: 'db', 'apc' and 'memcache'.
$rcmail_config['imap_cache'] = 'db';
// Enables messages cache. Only 'db' cache is supported.
$rcmail_config['messages_cache'] = true;

Rsync out of memory

Posted: 18/12/2012 in Shell tips

Do you have any problems when you use rsync to create incremental backups of your files?
Rsync uses a considerable amount of memory because of the recursive algorithm. The recursive algorithm that is used is an incremental scan that begins the file transfer after the scanning of the first few directories have been completed. If you use a VERY low memory vps for your backups you might have problems.
Incremental recursion can be disabled using the


option or its shorter


You also have to read these:

An easy and very useful command to automatically check, repair and optimize all tables in all mysql databases

mysqlcheck -u root -p --auto-repair --check --optimize --all-databases

I had a problem in my web-server vps.
I make daily compressed backups from my data and transferred them to another vps using tar and rsyc. I noticed high cpu usage nad load above 1.
After a little research i found this useful article and i will write here to find it easily:

“Anyone running a web server will either use a RAID for information protection, or will run a cron job that backups all the data daily

If you are running a budget server like mine, then most likely you’ll be doing daily backups. At 4 am everyday a backup process runs and stores a dump of the SQL and gzip of all the web folders including the SVN repository on a separate harddrive, which gets unmounted after the backup is done. The process takes around 2 hours to complete, during which the hard drives are all stressed and if the backup scripts were not carefully written they will hog any apache request due to slow disk access.

Run anacron as user

Posted: 18/04/2012 in Shell tips
Tags: ,

Anacron is a periodic command scheduler. It executes commands at intervals specified in days. Unlike cron, it does not assume that the system is running continuously. It can therefore be used to control the execution of daily, weekly and monthly jobs (or anything with a period of n days), on systems that don’t run 24 hours a day. When installed and configured properly, Anacron will make sure that the commands are run at the specified intervals as closely as machine-uptime permits. (more…)