Linux

Generate a /etc/hosts file from the command line

This is a simple example of how you can populate a /etc/hosts file with 100 IPs and hosts from the command line # N=1; for i in $(seq -w 100); do echo “192.168.99.$N host$i”; P=$(expr $P + 1); done >> /etc/hosts The result file /etc/hosts 192.168.99.201 host001 192.168.99.201 host002 192.168.99.201 host003 192.168.99.201 host004 192.168.99.201 host005 […]

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
Scripting

Script to customize a linux install

This is a simple bash script I whipped together to make som custom changes on our linux installations, it can be used as a kickstart post-configuration file for RedHat RHEL4 and RHEL5 installations. #!/bin/bash # Enable daily updates of the locate database perl -pi -e ‘s/DAILY_UPDATE=no/DAILY_UPDATE=yes/’ /etc/updatedb.conf # Customize login banners echo “Authorized users only. […]

Read More
Scripting

Restart dead daemon automatically

This is a simple bash script to restart a dead daemon, in this example I’ll use apache #!/bin/bash # Automatically restart httpd if it dies netstat -ln | grep “:80 ” | wc -l | awk ‘{if ($1 == 0) system(“/etc/init.d/httpd restart”) }’

Read More