Archive for 2011

sendenc – Send an encrypted email from the shell.

This script requires that you have a mail server configured on the machine your running it from.
#!/bin/bash
# Date: 03-18-2010
# Created by Dave Crouse

# Filename: sendencrypted
# Usage: sendencrypted
# Notes: Interactive- send passphrase encrypted email.

clear
echo "Send Passphrase Encrypted Email."
echo "------------------------------------------------"
read -p " Enter your email address: " replyto
read -p " Enter the email address you are sending to: " name
read -p " Enter the subject line of your email: " subject
echo "Enter the name/comment to put on the encrypted message. \
Just hit enter if you don't want any comments on it."
read -p "Note, this will be in clear text and readable by anyone! : " comment;
read -p "Hit ENTER to open vi and create your email." temp;

vi passphraseencryption
gpg --armor --comment "$comment" --no-options --output \
passphraseencryption.gpg --symmetric passphraseencryption
shred -u passphraseencryption

from="${replyto}"
emailthis=`cat passphraseencryption.gpg`

cat <<EOF | /usr/sbin/sendmail -f noreply -t
to:${name}
from:${from}
reply-to:${replyto}
subject: ENCRYPTED-${subject}
content-type: text/plain
${emailthis}
EOF

shred -u passphraseencryption.gpg
exit 0

Bash Server Ping Checking Script

# Pretty simple, add servers/ip’s/Ln (line numbers) in the format shown in the two column examples.
# Tested with over 50 servers, worked for what I needed, thought i’d share :)


#!/bin/bash
# Bash Server Ping Checking -written by Dave Crouse
# 09-24-2009 Crouse
# Pretty simple, add servers/ip's/Ln (line numbers) in the format shown in the two column examples.
# Tested with over 50 servers, worked for what I needed, thought i'd share :) ~~Crouse.

# Ideas --- ad another array for Headers. so Hn could print headers with bold/etc. Might be neat.
declare -a Sn # Server Name
declare -a Ip # IP address of server.
declare -a Ln # Line number to display on in Row1.
declare -a Sn2 # Server Name
declare -a Ip2 # IP address of server.
declare -a Ln2 # Line number to display on in Row2.
############################################################################### Server List Row 1
###############################################################################
Sn[1]="usalug.org"
Ip[1]="67.15.6.98"
Ln[1]="6"

Sn[2]="archlinux.me"
Ip[2]="208.92.232.122"
Ln[2]="7"
###############################################################################
###############################################################################

############################################################################### Server List Row 2
###############################################################################
Sn2[1]="usalug.org"
Ip2[1]="67.15.6.98"
Ln2[1]="6"

Sn2[2]="archlinux.me"
Ip2[2]="208.92.232.122"
Ln2[2]="7"
################################################################################
################################################################################
tput civis # Hide the cursor
maxcount=${#Sn[*]} #should report number of Servers listed in Sn variable
maxcount2=${#Sn2[*]} #should report number of Servers listed in Sn2 varialbe
clear
#tput setf 2; #echo -e '\e[1;33m'
echo " "
tput setf 0;tput setb 2;
echo " Bash Server Ping Checking Utility version 2.0 Crouse. "; #tput rmso;

tput setf 7; tput setb 0; # List out servers now.
for (( loop=1; $loop < $maxcount+1; loop++ ))
do
( tput cup ${Ln[$loop]} 10; echo "${Sn[$loop]}"; tput rc)
done
for (( loop2=1; $loop2 < $maxcount2+1; loop2++ ))
do
( tput cup ${Ln2[$loop2]} 50; echo "${Sn[$loop2]}"; tput rc)
done
# Set traps so when we exit the big ass loop stuffs normal again.
gracefulexit () {
tput cnorm;
tput setb 0;
echo "Stopping Application"
tput setf 2;
exit
}
trap gracefulexit INT TERM EXIT
# Begin big ass loop
while true
do
#First Row
for (( loop=1; $loop < $maxcount+1; loop++ ))
do
(tput sc ;tput setb 0; tput setf 0; tput cup 4 10 ;
echo "........................................................................";tput rc)
(tput sc ;tput setb 0; tput setf 6; tput cup 4 10 ;
echo "Checking ${Sn[$loop]} at IP: ${Ip[$loop]}" ; tput rc)
(tput sc ;tput setb 0; tput setf 0; tput cup ${Ln[$loop]} 1 ; echo "........." ; tput rc)
(tput sc ;tput setb 0; tput setf 6; tput cup ${Ln[$loop]} 1 ; echo "TESTING" ; tput rc)
count=$(ping -c 5 ${Ip[$loop]} | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
(tput sc ;tput setb 0; tput setf 0; tput cup ${Ln[$loop]} 1 ; echo "........." ; tput rc)
if [[ "$count" == [45] ]]; then
(tput sc ;tput setf 0; tput setb 2;tput cup ${Ln[$loop]} 5 ; echo " OK " ; tput rc)
else
if [[ "$count" == [123] ]]; then
(tput sc ;tput setf 0; tput setb 6; tput cup ${Ln[$loop]} 4 ; echo "ALERT" ; tput rc)
else
(tput sc ;tput setf 7; tput setb 4; tput cup ${Ln[$loop]} 2 ; echo "WARNING" ; tput rc)
fi
fi
done
#Second Row
for (( loop2=1; $loop2 < $maxcount2+1; loop2++ ))
do
(tput sc ;tput setb 0; tput setf 0; tput cup 4 10 ;
echo "........................................................................";tput rc)
(tput sc ;tput setb 0; tput setf 6; tput cup 4 10 ;
echo "Checking ${Sn2[$loop2]} at IP: ${Ip2[$loop2]}" ; tput rc)
(tput sc ;tput setb 0; tput setf 0; tput cup ${Ln2[$loop2]} 41 ; echo "........." ; tput rc)
(tput sc ;tput setb 0; tput setf 6; tput cup ${Ln2[$loop2]} 41 ; echo "TESTING" ; tput rc)
count2=$(ping -c 5 ${Ip2[$loop2]} | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
(tput sc ;tput setb 0; tput setf 0; tput cup ${Ln2[$loop2]} 41 ; echo "........." ; tput rc)
if [[ "$count2" == [45] ]]; then
(tput sc ;tput setf 0; tput setb 2;tput cup ${Ln2[$loop2]} 45 ; echo " OK " ; tput rc)
else
if [[ "$count2" == [123] ]]; then
(tput sc ;tput setf 0; tput setb 6; tput cup ${Ln2[$loop2]} 44 ; echo "ALERT" ; tput rc)
else
(tput sc ;tput setf 7; tput setb 4; tput cup ${Ln2[$loop2]} 42 ; echo "WARNING" ; tput rc)
fi
fi
done
done

Bash – a quick stock quote function

Wrote this and stuck it in my .bashrc file so I could get a realtime stock quote quickly from my shell sessions.

stock ()
{
lynx -dump "http://www.google.com/finance?client=ob&amp;q=${1}" | sed 's/.*']'//' | \
perl -00ne "print if /Watch this stock/i" | sed 's/Watch this stock//' | sed 's/Disclaimer//' | \
sed '/^$/d' | sed 's/Currency in USD//'
}

crouse@archie stock slv

slv
30.26
+0.08 (0.27%)
Real-time: 11:41AM EST

1. Range 30.14 – 30.44
2. 52 week 14.37 – 30.44
3. Open 30.29
4. Vol / Avg. 9.57M/26.84M
5. Mkt cap 9.73B
6. P/E 95.32
7. Div/yield -
8. EPS 0.32
9. Shares 321.50M
10. Beta 0.38
11. Inst. own 25%

TIP: Ever get those strange characters in your console ?

Ever get those strange looking little buggers in your console after installing Arch and firing up the terminal ?
Something like this –
[crouse@archie ~]$ pstree
init─┬─6*[agetty]
├─crond
├─httpd───11*[httpd]
├─mysqld_safe───mysqld───9*[{mysqld}]
├─sshd─┬─sshd───sshd───bash───su───bash
│ └─sshd───sshd───bash───pstree
├─syslog-ng───syslog-ng
├─udevd───udevd
└─vmtoolsd

Simply add the following to your .bashrc and close your terminal window and open it up again, or source the .bashrc file again.
export LC_ALL=C

[crouse@archie ~]$ pstree
init-+-6*[agetty]
|-crond
|-httpd---11*[httpd]
|-mysqld_safe---mysqld---9*[{mysqld}]
|-sshd-+-sshd---sshd---bash---su---bash
| `-sshd---sshd---bash---pstree
|-syslog-ng---syslog-ng
|-udevd---udevd
`-vmtoolsd
[crouse@archie ~]$

Getting a listing of blogs on Archlinux.me

An easy way to get a listing of all the current blogs in the system.

[crouse@archie ~]$ cat archme.sh
#!/bin/bash
dbase=`mysql -u USERNAME -pPASSWORD -e"use wordpress; select path from wp_blogs;"`
for data in $dbase ;
do
echo "http://archlinux.me${data}"
done
[crouse@archie ~]$ ./archme.sh  | grep -v http://archlinux.mepath | sort
http://archlinux.me/
http://archlinux.me/anikom15/
http://archlinux.me/anubis2591/
http://archlinux.me/aymara/
http://archlinux.me/bionicapple/
http://archlinux.me/brain0/
http://archlinux.me/crouse/
http://archlinux.me/cyrusm/
http://archlinux.me/dickturpin/
http://archlinux.me/drcouzelis/
http://archlinux.me/dusty/
http://archlinux.me/edgar/
http://archlinux.me/emallson/
http://archlinux.me/fallenwizard/
http://archlinux.me/gnuisancev3/
http://archlinux.me/hatten/
http://archlinux.me/heleos/
http://archlinux.me/itsbrad212/
http://archlinux.me/jada/
http://archlinux.me/jbsnake/
http://archlinux.me/jdarnold/
http://archlinux.me/jimi/
http://archlinux.me/jp/
http://archlinux.me/kaptenen/
http://archlinux.me/kcirick/
http://archlinux.me/killerturtle/
http://archlinux.me/kittykatt/
http://archlinux.me/lordmetroid/
http://archlinux.me/msx/
http://archlinux.me/nblock/
http://archlinux.me/neonskull/
http://archlinux.me/panuh/
http://archlinux.me/peasantoid/
http://archlinux.me/platinummonkey/
http://archlinux.me/procyon/
http://archlinux.me/requiem/
http://archlinux.me/ronald/
http://archlinux.me/shadowtracer/
http://archlinux.me/shemz/
http://archlinux.me/staerseus/
http://archlinux.me/sudobash/
http://archlinux.me/tajidinabd/
http://archlinux.me/theisz/
http://archlinux.me/theringmaster/
http://archlinux.me/usedtire/
http://archlinux.me/wonder/

Completed the Server Move

Finally completed the server move.

All blogs have been moved that were in use.
Now everything is running on wordpress 3.x multisite enabled.