msgbartop
A cronological documentation test project, nothing serious, really!
msgbarbottom

25 Feb 2008 My 10 most used linux commands

This is a oneliner bash command to determine my 10 most used linux commands according to my history file

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10

The result

     1  188  37.6%  vi
     2  38   7.6%   ls
     3  24   4.8%   cat
     4  22   4.4%   apt-get
     5  12   2.4%   date
     6  11   2.2%   tail
     7  11   2.2%   cd
     8  10   2%     rm
     9  10   2%     man
    10  9    1.8%   basename

It looks like i use vim a lot on my home server. You should try it yourself and see what commands you use the most.

Source: http://linux.byexamples.com

Tags: , , , , , ,

Posted by Hans-Henry Jakobsen

21 Feb 2008 Apache web connections pr hour

This is a bash oneliner to show Apache web connections pr hour. It lists up the IPs that has accessed your webserver and the amount og accesses.

# cat /var/log/apache2/access_log_pario.no | grep "21/Jan/2008:.." | awk {' print $4":"$1 '} | sed 's/\[//g' | awk -F : {' print $1":"$2"\t\t"$5 '} | sort | uniq -c

Example output

37 21/Jan/2008:00          192.168.0.10

This shows that I had 37 hits from 00:00 – 01:00 in 20th February 2008.

Tags: , , , ,

Posted by Hans-Henry Jakobsen

04 Dec 2007 Strip the kernel to contain only needed modules

This is a great page with som nice bash scripts describing how to remove unwanted modules from your kernel.

Tags: , , , , , , ,

Posted by Hans-Henry Jakobsen

18 Nov 2007 Backup mysql databases into separate files

This bach script makes separate backup files of all the databases in mysql and saves the result in the mysql_backup folder.

#!/bin/bash -v

USERNAME='yourusername'
PASSWORD='yourpassword'
HOSTNAME='yourhostname'
BackupFolder='/backup'

for i in $(echo 'SHOW DATABASES;' | mysql --user $USERNAME -p$PASSWORD -h $HOSTNAME | grep -v '^Database$' ); do
        mysqldump --user $USERNAME -p$PASSWORD -h $HOSTNAME --opt $i > $BackupFolder/$i.sql;
done;

Remember to change the -h, -p and -h switch according to your needs and avoid space between -p and the password variable.

Tags: , , , , ,

Posted by Hans-Henry Jakobsen

01 Nov 2007 Grep recursively through subdirectories

grep recursively through subdirectories for files that match a specific pattern:

grep -l -r –include=*.doc regex *

The equivalent command unsing find:

find . -name ‘*.doc’ -exec grep -l regex \{\} \;

The option after grep is the lowercase letter L, not the number 1).
Remove the -l to see the actual matches instead of the file names.

Tags: , ,

Posted by Hans-Henry Jakobsen