Linux

Windows grep command alternative

grep is a linux console command to print lines matching a line, but Windows does not have the grep command. In Windows you have to use the findstr command in a console window. Example C:\>dir |findstr Windows 13.09.2011 10:41 Windows The findstr command is default case sensitive just like in linux. findstr options C:\>findstr -? […]

Read More
Linux

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 […]

Read More
Scripting

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 […]

Read More
Linux

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 > […]

Read More