sed delete all lines after

Objective: Prep dev httpd.conf for production


Remove jenkins virtual host entry (which starts with a comment line “#Start Jenkins”) Replace .dev with nothing (ex: becomes Replace debug with error (ex: Loglevel debug becomes Loglevel error) Sed to remove lines after match

In this example we will use sed delete all lines after . . . → Read More: sed delete all lines after

redhat add multiple users

useradd script

to add multiple users to a system and force them to change their password upon login try the following script:

Redhat # for name in someuser anotheruser yetanotheruser; do useradd $name; echo ‘password’ | passwd –stdin $name; chage -d 0 $name; done

The above script will add three users to the system (someuser . . . → Read More: redhat add multiple users

Bash Server Backup Script

I’ve created a Bash Server Backup Script that will backup your MySQL databases (each database separately in to .sql and .xml files) and your main directories (/var/log, /var/www/html, /etc, /home, /root) to a timestamped directory. Feel free to re-use or hack up however you’d like

Here’s my Bash Server Backup Script: Download the script here

. . . → Read More: Bash Server Backup Script

parse apache access log entries to find top user agents, top urls and top IPs

This script will allow you to see the top user agents, urls, IPs for your log files:


Script name: ls-httpd

#!/bin/bash # Usage # ls-httpd type count # Eg: # ls-httpd url 1000 # will find top URLs in the last 1000 access log entries # ls-httpd ip 1000 # will find top IPs . . . → Read More: parse apache access log entries to find top user agents, top urls and top IPs

kill liferay script

Here’s a bash kill liferay script!

This should kill any running liferay or liferay social office on a linux system.

Open up your favorite editor and paste this in

#!/bin/bash # #Script name: # #Purpose: To kill any running instance of liferay on a linux system # #Usage: ./ # for pid in `ps . . . → Read More: kill liferay script

gzip log files older than one day

To Gzip files older than one day place this in a cronjob: TODAY=`date +”%Y-%m-%d”`

for logfile in /var/log/tomcat6/*.log; do # grab the %Y-%m-%d out of the name DTS=${logfile:(-14):10} if [ $DTS != $TODAY ]; then # compress in place gzip $logfile fi done

kill orphaned httpd processes

to kill orphaned httpd processes create a script called with the following code

#!/bin/bash for pid in `ps -C httpd|sed -e ‘s/^\ \+//g’ | grep httpd|awk ‘{print $1}’` do kill $pid done

bash diff alternative

How to setup a bash diff alternative nano -w /usr/bin/diff2

Copy and paste the below in to /usr/bin/diff2

#!/bin/bash # # name: # usage: ./ file1 file2 # To make available to whole system copy to /usr/local/bin # and rename to diff2 # colorize diff output for ANSI terminals # based on “diff2html” # . . . → Read More: bash diff alternative