Recently I tried passing a bash variable to perl command in bash script, it didn’t end well.
Troy Engel from http://tacticalvim.wordpress.com/ was nice enough to point out the issue:
use sed instead of perl for what you need; it’s simpler, faster and uses the bash variables easily.
I set up a test script /home/someuser/test.sh to show:
. . . → Read More: passing bash variable to perl command in bash script
posted this in Apache, bash, Linux, Redhat Centos on October 26th, 2012 Objective: Prep dev httpd.conf for production
Tasks:
Remove jenkins virtual host entry (which starts with a comment line “#Start Jenkins”) Replace .dev with nothing (ex: www.dev.example.com becomes www.example.com) 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
posted this in bash, Linux, Redhat Centos, Ubuntu on September 13th, 2012 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 anotheruser yetanotheruser) with the password “password” and set the password age to zero. This forces them to change their password . . . → Read More: redhat add multiple users
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
posted this in bash, Linux, Redhat Centos, Scripts, Ubuntu on March 7th, 2012 This script will allow you to see the top user agents, urls, IPs for your log files:
Script name: ls-httpd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#!/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 in the last 1000 access log entries # ls-httpd agent 1000 # will find top user agents in the last 1000 access log entries type=$1 length=$2 if [ "$3" == "" ]; then log_file="/var/log/httpd/some-access_log" else log_file="$3" fi if [ "$type" = "ip" ]; then tail -n $length $log_file | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | sort -n | uniq -c | sort -n elif [ "$type" = "agent" ]; then tail -n $length $log_file | awk -F\" '{print $6}'| sort -n | uniq -c | sort -n elif [ "$type" = "url" ]; then tail -n $length $log_file | awk -F\" '{print $2}'| sort -n | uniq -c | sort -n fi |
posted this in bash, Linux, Redhat Centos, Scripts, Ubuntu on December 19th, 2011 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: kill_liferay.sh # #Purpose: To kill any running instance of liferay on a linux system # #Usage: ./kill_liferay.sh # for pid in `ps . . . → Read More: kill liferay script
posted this in bash, Linux, Redhat Centos, Scripts on December 19th, 2011 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
posted this in bash, FreeBSD, Linux, Redhat Centos, Scripts, Ubuntu on December 5th, 2011 to kill orphaned httpd processes create a script called killhttpd.sh 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 |
posted this in bash on July 6th, 2011 How to setup a bash diff alternative
Copy and paste the below in to /usr/bin/diff2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#!/bin/bash # # name: diff2.sh # usage: ./diff2.sh 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" # (http://www.linuxjournal.com/content/convert-diff-output-colorized-html) # absolute color definitions NOCOL="\e[0m" BOLD="\e[1m" RED="\e[31m" BLUE="\e[34m" PINK="\e[35m" CYAN="\e[36m" WHITE="\e[37m" # style color definitions C_COMMENT=$WHITE C_DIFF=$RED C_OLDFILE=$CYAN C_NEWFILE=$RED C_STATS=$BLUE C_OLD=$BOLD$RED C_NEW=$BOLD$BLUE C_ONLY=$PINK # check args [[ $# -lt 2 ]] && echo "Usage: $0 file1 file2" && exit 1 # The -r option keeps the backslash from being an escape char. diff -u $@ | while read -r s ; do # determine line color if [[ "${s:0:7}" == 'Only in' ]]; then color=$C_ONLY elif [[ "${s:0:4}" == 'diff' ]]; then color=$C_DIFF elif [[ "${s:0:3}" == '---' ]]; then color=$C_OLDFILE elif [[ "${s:0:3}" == '+++' ]]; then color=$C_NEWFILE elif [[ "${s:0:2}" == '@@' ]]; then color=$C_STATS elif [[ "${s:0:1}" == '+' ]]; then color=$C_NEW elif [[ "${s:0:1}" == '-' ]]; then color=$C_OLD else color= fi # Output the line. if [[ "$color" ]]; then printf "$color" echo -n $s printf "$NOCOL\n" else echo $s fi done |
Now make it executable
Example Usage:
|
|
# bash -c 'diff2 < (sort file2) <(sort file1)' |
|
|