Archive for category Programming
My EC2 EBS RAID-0 creation script
Posted by Jon Zobrist in AWS, Bash, EBS, EC2, Linux, Linux Support - Servers, Programming on May 4, 2011
I want to write up a full howto/tutorial, but have not had the time.
Here is the script that I referred to in my post at http://www.jonzobrist.com/2011/04/16/ec2-raid0-on-linux-with-ebs-volumes-notes/
This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License HERE for more details.
http://www.jonzobrist.com/files/setup-ec2-raid-0.zip
http://www.jonzobrist.com/files/setup-ec2-raid-0.sh.gz
This script needs an AWS command line setup, and may need some minor tweaking if you’re not running a Ubuntu server.
Ubuntu’s latest AMI’s are available for 10.04 here.
Please feel free to submit patches, comments, or questions.
Thanks to everyone whose helpful posts online and in the AWS forums helped me with this script. I could not have done it with out your generous sharing of work.
Enjoy!
15 Incredible WordPress Plugins
Posted by Jon Zobrist in PHP, Wordpress on April 16, 2011
I love WordPress, and I am constantly impressed by the quality and functionality in both WordPress and the many plugins that are out there. I just found this awesome list of WordPress Plugins at sitesketch101.com.
http://www.sitesketch101.com/15-incredible-wordpress-plugins-you-need
Thanks Nicholas Cardot @ Site Sketch 101!
S3-du.sh script to get bucket size on Amazon AWS S3
Posted by Jon Zobrist in AWS, Bash, FreeBSD, Linux, Programming, S3 on March 19, 2011
Here is my script s3-du.sh that I wrote to determine how big a bucket is on Amazon S3. I’m sure there are other ways to skin this cat, but I wrote this and figured I’d share it. Feel free to use it under any free license.
Requires you to have a working s3ls and your Amazon AWS credentials setup already. I use Tim Kays AWS tools.
Links to the file as text, as gzip, as zip.
#!/bin/bash
if [ "${1}" ]
then
NUM=0
COUNT=0
for N in `s3ls ${1} | awk ‘{print $11}’ | grep [0-9]`
do
NUM=`expr $NUM + $N`
((COUNT++))
done
KB=`expr ${NUM} / 1024`
MB=`expr ${NUM} / 1048576`
GB=`expr ${NUM} / 1073741824`
echo “${COUNT} files in bucket ${1}”
echo “${NUM} B”
echo “${KB} KB”
echo “${MB} MB”
echo “${GB} GB”
else
echo “Usage : ${0} s3-bucket”
exit 1
fi
LCOD – 11.17.09 – Simple page/alert email script
Posted by Jon Zobrist in Bash, Linux, Linux Command of the Day, Programming on November 17, 2009
Here’s a quick page script for *nix boxes with mail.
I grabbed the mail / file redirect from
http://theos.in/shell-scripting/send-mail-bash-script/
#!/bin/bash
#Author : dougnaka@gmail.comThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it
#Description : Quick alert/page script, edit EMAIL="" to include a comma separated list of emails to send to
#Usage : page.sh "Short or long message"
if [ "${1}" ]
then
SUBJECT="[ALERT] ${1}"
EMAIL=" someone@example.com"
EMAILMESSAGE="/tmp/`date +%s`-message"
echo "ALERT: at `date`" > ${EMAILMESSAGE}
echo "${1}" >> ${EMAILMESSAGE}
echo "From `hostname`" >> ${EMAILMESSAGE}
mail -s "${SUBJECT}" "${EMAIL}" < ${EMAILMESSAGE}
/bin/rm ${EMAILMESSAGE}
else
echo "Usage: ${0} MESSAGE"
exit 1
fi
LCOD 11.14.07 – Quick RAID check script for cron
Posted by Jon Zobrist in Bash, Linux, Linux Command of the Day, Programming on November 14, 2007
This is a quick script that will let you run the new raid checks, or repair, or pause a running raid check. It doesn’t do e-mails or anything, and from what I read on this thread it’s something mdadm needs to be set to watch for. I ran the check on a RAID and received no output, so I guess it was ok?
I will update the script as I find out more. I’d like to add a simple escalation from check to rebuild? (I think it does this anyways), and an e-mail status report, or even a syslog call saying I ran all things look good.
#!/bin/bash
###############
# Quick script to use raid functionality
# Author : Jon Zobrist < jon@bluesun.netThis e-mail address is being protected from spam bots, you need JavaScript enabled to view it >
# http://www.bluesun.net/
# License : LGPL
# Version : 1.0
# Date : 11.14.07
# install/notes:
# put it somewhere, /root/bin/ is where I prefer
# put this in your root crontab to run from cron monthly
# @monthly /root/bin/checkraids check > /root/logs/cron.log 2>&1
###############
case "$1" in
check)
for raid in /sys/block/md*/md/sync_action
do
echo check > $raid
done
;;
repair)
for raid in /sys/block/md*/md/sync_action
do
echo repair > $raid
done
;;
pause)
for raid in /sys/block/md*/md/sync_action
do
echo idle > $raid
done
;;
status)
for raid in /sys/block/md*/md/sync_action
do
echo "******************************"
echo $raid `cat $raid`
echo ""
done
;;
*)
echo "Usage : $0 check|repair|pause|status"
;;
esac
LCOD – 5.9.07 – Updating CPAN in Perl
Posted by Jon Zobrist in Linux, Linux Command of the Day, Perl, Programming on May 9, 2007
Perl rocks, it’s easily my favorite programming language. One of the nice things about Perl is the CPAN (Comprehensive Perl Archive Network). Your Linux box has CPAN installed already, and to begin using it you should first update it. To do so run the commands just below. The first time you invoke CPAN it’ll launch the configuration module, just hit enter until it gets into the part about which mirrors you want to use, it’ll have you pick geographic areas first, and then tell you to enter servers by number, separated by spaces. I usually put in about 20 servers, which looks like kinda this
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10
#invoke perl’s CPAN shell (and first time configuration with)
bash$ perl -MCPAN -e shell
#once configuration is done, update CPAN, and then reload
CPAN> install Bundle::CPAN
CPAN> reload cpan
Now, head on over to CPAN and search for some cool new Perl modules to play with!
A great place to dive into the world of Perl is Perl.org
Also the Perl Monks is a good Perl site, and Use Perl is as well.
Make sure you have a correct build environment setup, on Ubuntu/Debian you need to install the build-essential package (sudo apt-get install build-essential)
LCOD – 2.18.07 – Simple command line perl substitutions
Posted by Jon Zobrist in Linux, Linux Command of the Day, Perl, Programming on February 18, 2007
first, make a file that lists all the images (we’re using *jpg, but you could do *gif, or *coolimages*, or just * for all files in the dir – note: all files in dir * with a redirect will catch the file you are redirecting to, and it will likely need to be removed)
From the shell / command line, run:
/bin/ls *jpg > ourfiles
Now the fun part! This will take a line like this
picture1.jpg
And make it look like this
<a href=”picture1.jpg”><img src=”picture1.jpg” border=”0″></a>
From the shell run / command line, run:
perl -pi -e ‘s/^(.*)$/<a href=\”$1\”><img src=\”picture1.jpg\” border=\”0\”><\/a>/’ ourfiles
The basic pattern of this command is
‘s/SEARCH PATTERN REGEX/REPLACEMENT PATTERN/’
The search pattern is a Regular Expression, and the Replacement Pattern needs to have any special characters escaped (including / $ # @ “) with a \
The Search Pattern we’re using is a simple one ^ for start of line, (.*) for . anything and * any number of times, with paranthesis around it to put it into the perl variable $1, and $ for end of line.
