Posted by M@ on 2009/05/08
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# lappyVonRsync
# SYNOPSIS -
# `15 1 * * * /home/username/scripts/lappyVonRsync`
# DESCRIPTION -
# To keep my NFS share in sync with my laptop ~
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# I only allow the sync to occur if my laptop is hard wired and on my internal network.
# My home
HOMEDIR="/home/username/"
SHARENAME="/Share/username"
SERVER="192.168.227.254"
# Look at the eth0 to see if the system is on my internal network.
/sbin/ifconfig eth0 | egrep "192.168.227"
# Since it is start the rsync.
if [ $? == "0" ]; then
# rsync command
rsync -vaz --exclude-from="${HOMEDIR}.rsync/exclude" -e ssh --delete ${HOMEDIR} ${SERVER}:${SHARENAME}
fi
Posted by M@ on 2009/05/02
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# storemd5
# SYNOPSIS -
# This should really go in your local users crontab
# `*/20 * * * /PATH/TO/storemd5`
# DESCRIPTION -
# Because WP e-commerce does not work well with very large files.
# This will allow you to upload the files using scp/ftp and then process them.
# It's best to use a staging directory then move the completed files to 'upload'
# REVISIONS -
# Only one published at this time.
# Define your web directory
WEBDIR="/home/username/www/example.com"
# Where is your store located
STOREDIR="/home/username/www/example.com/wp-content/uploads/wpsc/downloadables"
# Define your upload directory
UPLOADDIR="/home/username/example-store/upload"
# Check to ensure that folders needed are there
if [ ! -d ${STOREDIR} ]; then
mkdir -p ${STOREDIR}
fi
if [ ! -d ${SQLDIR} ]; then
mkdir -p ${SQLDIR}
fi
if [ ! -d ${UPLOADDIR} ]; then
mkdir -p ${UPLOADDIR}
fi
# In case of multiple files the for loop begins.
for i in `ls ${UPLOADDIR}`; do
# Change to the upload directory to just make it easier.
cd ${UPLOADDIR}
# Manipulate the file name
NEWNAME=`md5sum $i | awk '{print $1}'`
EXTNAME=`echo $i | awk -F. '{print $2}'`
IDNAME=`echo $i | awk -F. '{print $1}'`
# Pull your database information from the wordpress installation
DBNAME=`egrep "DB_NAME" ${WEBDIR}/wp-config.php | awk '{print $2}' | awk -F\) '{print $1}'| cut -c 2- | awk -F"'" '{print $1}'`
DBUSER=`egrep "DB_USER" ${WEBDIR}/wp-config.php | awk '{print $2}' | awk -F\) '{print $1}'| cut -c 2- | awk -F"'" '{print $1}'`
DBPWD=`egrep "DB_PASSWORD" ${WEBDIR}/wp-config.php | awk '{print $2}' | awk -F\) '{print $1}'| cut -c 2- | awk -F"'" '{print $1}'`
# Current date
DATE4=`date +%D`
# Move the file with it's new md5sum name to the web store
mv $i ${STOREDIR}/${NEWNAME}
# Insert the information about the file into the database.
mysql -u ${DBUSER} --password=${DBPWD} ${DBNAME} <
Posted by M@ on 2009/05/02
#!/bin/bash
# AUTHOR -
# Some Internet Cat I can't find the link to now. Modifications made by
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# mysql_dumper
# SYNOPSIS -
# `15 1 * * * /home/username/scripts/lappyVonRsync`
# DESCRIPTION -
# As my web directory is larger than 2gig it falls
# outside of the 'Complimentary' backups from my hosting company.
# This simply backs up all of my mysql databases nightly.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# TBD
# Where should the dumps be saved
DIR="/home/username/backups/mysql/"
# Date stamp for the name
DATESTAMP=$(date +%Y%m%d)
# Database username
DB_USER=username_backer
# Database password
DB_PASS='mysqlpassword'
# Remove backups older than $DAYS_KEEP
DAYS_KEEP=2
# Find any files older then $DAYS_KEEP
find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2> /dev/null
# Create backups securely
umask 006
# List MySQL databases and dump each
DB_LIST=`mysql -u $DB_USER -p"$DB_PASS" -e'show databases;'`
DB_LIST=${DB_LIST##Database}
# Loop to dump all known databases
for DB in $DB_LIST;
do
FILENAME=${DIR}${DB}-${DATESTAMP}.sql.gz
mysqldump -u $DB_USER -p"$DB_PASS" --opt $DB | gzip > $FILENAME
done
Posted by M@ on 2009/05/02
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# backup_site
# SYNOPSIS -
# `15 1 * * * /home/username/scripts/backup_site`
# DESCRIPTION -
# As my web directory is larger than 2gig it falls
# outside of the 'Complimentary' backups from my hostinf company.
# This simply uses 'rsync' with an ssh key to backup the
# directory in a folder per-day
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# TBD
# Pull the Day 'Mon','Tue' and so on
DATE=`date +%a`
# Where should backups save
BACKUPDIR="/Share/Media/WebBackups"
# What is the username and server
SERVER="username@sprackle.org"
# Server web directory
WEBDIR="/home/username"
# Check to ensure that the backup directory exists
if [ ! -d ${BACKUPDIR}/${DATE} ]; then
# Since it's not there create it
mkdir -p ${BACKUPDIR}/${DATE}
fi
# rsync command
rsync -ave ssh --delete ${SERVER}:${WEBDIR} ${BACKUPDIR}/${DATE}/
Posted by M@ on 2009/04/27
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# rpm_verify
# SYNOPSIS -
# `15 1 * * * /home/username/scripts/rpm_verify`
# DESCRIPTION -
# Check all the RPMs installed on this system by trusted
# and ensure that the packages were signed by a trusted source.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# I plan on putting some file checking at a later date.
# Trusted Keys seperated by a pipe
TRUSTKEY="5326810137017186|219180cddb42a60e"
for i in `rpm -qa`
do
rpm -qi $i | egrep $TRUSTKEY
if [ $? != 0 ];
then
echo "RPM $i not signed by trusted key" >> /tmp/KeyResults
fi
done
Posted by M@ on 2009/04/27
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# permadoc
# SYNOPSIS -
# `./permadoc`
# DESCRIPTION -
# To backup and document all permissions of a directories
# and create a script to fix the permissions in case of a problem.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# TBD
# Use:
# Limitations: TBD
#
# Directory to scan.
DIRECTORY="/home/"
for i in `find $DIRECTORY -type d`;
do
cd $i
echo "cd $PWD" >> /tmp/current_perms
ls -ls $PWD | awk '{print "chown",$4":"$5,$10}' | egrep -v "^:" >> /tmp/current_perms
done
Posted by M@ on 2009/04/27
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# gpgDo
# SYNOPSIS -
# `./gpgDo FILENAMETOWORKWITH`
# DESCRIPTION -
# A quick script for those who can't remember the GPG commands.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# TBD
# My email address
MYEMAIL="m@sprackle.org"
#
select GPGCALL in "Decrypt_file" "Encrypt_file" \
"Encrypt_file_to_person_in_key_store" "Encrypt_with_symmetric_phrase";
do
[ -z "${GPGCALL}" ] && echo "Please enter a vaild number" || break;
done
#
function Decrypt_file () {
gnome-terminal --command="gpg --output ./$@.out --decrypt ./$@"
}
#
function Encrypt_file () {
gpg --recipient $MYEMAIL --armor --encrypt "$@"
}
#
function Encrypt_file_to_person_in_key_store () {
echo "$(gpg --list-keys)"
gnome-terminal --command="gpg --armor --encrypt $@"
}
#
function Encrypt_with_symmetric_phrase () {
gpg -c "$@"
}
$GPGCALL
Posted by M@ on 2009/04/27
- – Had to make a few changes..
I wanted to be lazy and get some setup scripts in order for me to study for my exams. So I started with this script to help me setup some lab systems.
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# lazyLab
# SYNOPSIS -
# `./lazyLab FUNCTIONTOCALL`
# DESCRIPTION -
# I needed a quick way to deploy things to my lab machines.
# I only have 4 so the for loop stops at 24. Change the sequence number
# to more if you need it.
# To add anything just copy the reboot function. Name it and put in the
# commands you may want to send.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
IPADDR='192.168.32'
ISCSISERVER='$IPADDR..20'
for i in $(seq 4)
do
#
function reboot () {
# reboot all the systems
echo "shutdown -r now" | ssh root@$IPADDR.2$i /bin/bash
# End reboot
}
#
function ricci () {
# Install ricci
echo "yum install ricci -y" | ssh root@$IPADDR.2$i /bin/bash
echo "service start ricci" | ssh root@$IPADDR.2$i /bin/bash
# End ricci install
}
#
function keys () {
# Deploy the SSH key
echo "mkdir /root/.ssh" | ssh root@$IPADDR.2$i /bin/bash
scp authorized_keys root@$IPADDR.2$i:/root/.ssh/authorized_keys
echo "chmod -R 600 /root/.ssh" | ssh root@$IPADDR.2$i /bin/bash
scp sshd_config root@$IPADDR.2$i:/etc/ssh/sshd_config
echo "/etc/init.d/sshd restart" | ssh root@$IPADDR.2$i /bin/bash
# Deployment of key stop
}
function update () {
# Deploy repo for updates and update
scp dag.repo root@$IPADDR.2$i:/etc/yum.repos.d/dag.repo
scp RPM-GPG-KEY.dag.txt root@$IPADDR.2$i:~/
echo "rpm --import ~/RPM-GPG-KEY.dag.txt" | ssh root@$IPADDR.2$i /bin/bash
echo "yum update -y &" | ssh root@$IPADDR.2$i /bin/bash &
# End updates
}
function iscsi () {
# Setup my iscsi targets
iscsiadm --mode discovery --type sendtargets --portal $ISCSISERVER
iscsiadm --mode node --targetname iqn.2009-03.org.sprackle:1 --portal $ISCSISERVER:3260 --login
iscsiadm --mode node --targetname iqn.2009-03.org.sprackle:2 --portal $ISCSISERVER:3260 --login
iscsiadm --mode node --targetname iqn.2009-03.org.sprackle:3 --portal $ISCSISERVER:3260 --login
# End Setup of iscsi targets
}
$1
done
Posted by M@ on 2009/04/27
- – Had to update version 5 to resolve the loop. Seems you need a >/dev/null after the ffmpeg.
So I wanted a script to convert all of my video files so I could watch them on my iPhone. I came up with this nautilus script.
#!/bin/bash
# AUTHOR: M@sprackle.org
# PURPOSE: To convert one file or many files to iphone format and size.
# LIMITATIONS: Get the Cancel button working in Zenity pop-up
# INSTALL: Place this script in "~/.gnome2/nautilus-scripts/iPhone"
# and set to execute `chmod +x ~/.gnome2/nautilus-scripts/iPhone`
# USE: Just right click on a file or folder that contains files you
# would like to convert to an iPhone/iTouch format.
#
# Where do you want all of these files to be saved?
# You should NOT have to edit below this line
IPHONESAVESPOT="/home/mwells/iPhoneMovies"
#
# Same as above I just wanted a single place to find my files
if [ ! -d $IPHONESAVESPOT ]; then
mkdir $IPHONESAVESPOT
fi
# Lets see if this was a single file or a Directory
if [ -f "$1" ]; then
#
# Let's cut up the name so it's not example.avi.mp4
NEWNAME=`echo "$1" | awk -F. '{print $1}'`
#
# Run the command - I found all these flags on some website.
# So far they're good.
ffmpeg -y -threads 4 -i "$1" -r 29.97 -vcodec libx264 -s 480x272 \
-flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 24 \
-bt 256k -refs 1 -coder 0 -me umh -me_range 16 -subq 5 \
-partitions +parti4x4+parti8x8+partp8x8 -g 250 -keyint_min 25 \
-level 30 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 \
-i_qfactor 0.71 -acodec libfaac -ab 128k -ar 48000 -ac 2 \
$IPHONESAVESPOT/"$NEWNAME".mp4
Posted by M@ on 2009/04/27
I wanted an easy script for backing up my legal DVDs with Handbrake.
This script dumps to ipod format and I know tt needs work and i’ve not even tested the multi-disc function.
#!/bin/bash
# AUTHOR -
# M@ - M@sprackle.org GPG Public Key ID: 0x4ADEA413
# NAME -
# handbreaker
# SYNOPSIS -
# ./handbreaker
# DESCRIPTION -
# I just wanted to make the script so my wife could use it.
# REVISIONS -
# Only one published at this time.
# LIMITATIONS -
# TBD
# Backup Dir
BACKUPDIR="/Share/Media/Movies"
# Whats your DVD ROM?
DVDROM='sr0'
#
#Make sure that it's mounted
mount | grep $DVDROM > /dev/null 2>&1
if [ $? != "0" ]
then
mount /dev/$DVDROM /mnt
echo " I had to mount the DVD"
fi
#
# Help out the non-CLI people
echo "
What is the name of the DVD?
EXAMPLE: Lord of the rings
"
read DVDNAME
clear
#
# Clean up those spaces
export DVD_NAME=`echo $DVDNAME | tr [:blank:] '_'`
#
echo "
Is this part of a box set with multiple DVDs?
y/n
"
read MULTIDISC
if [ $MULTIDISC = "y" ]
then
clear
echo "
How many DVDs are in the set?
"
read NUMBER
export DISC_NUMBER="1"
export TOTAL_NUMBER=$NUMBER
#
# Let's keep a running list of the movies we've backed up.
for((i=0;$i<=$TOTAL_NUMBER;i=$(($i+1))));do
#
# Lets see if I've done this one.
grep -i Disc_$DISC_NUMBER_$DVD_NAME $BACKUPDIR/Movie_List.txt
if [ $? = "1" ]
then
echo "
I've already backed this one up insert new disc.
Sorry to say I'm just not cool enough to start
over so i'm just going to exit and restart this.
"
eject /mnt
exit 1
fi
#
# Lets loop this one
mkdir -p $BACKUPDIR/Disc_$DISC_NUMBER_$DVD_NAME
/usr/bin/HandBrakeCLI -i /dev/sr0 -o \
$BACKUPDIR/Disc_$DISC_NUMBER_$DVD_NAME/Disc_$DISC_NUMBER_$DVD_NAME.mp4 \
-e x264 -b 1500 -E faac -B 160 -R 48 -f mp4 -m -p -2 -T -x ref=2:bframes=2:subme=5:me=umh
echo $DISC_NUMBER_$DVD_NAME >> $BACKUPDIR/.movie_list.txt
cat $BACKUPDIR/.movie_list.txt | sort > $BACKUPDIR/Movie_List.txt
eject /mnt
done
else
#
# Let's also see if we've already backed up this movie
grep -i $DVD_NAME $BACKUPDIR/Movie_List.txt
#
if [ $? = "0" ]
then
echo " I've already backed this one up"
exit 1
unset DVD_NAME
fi
#
# Lets make the Directory needed
mkdir -p $BACKUPDIR/$DVD_NAME
#
# Lets get to backing up are legal DVD
/usr/bin/HandBrakeCLI -i /dev/sr0 -o $BACKUPDIR/$DVD_NAME/$DVD_NAME.mp4 \
-e x264 -b 1500 -E faac -B 160 -R 48 -f mp4 -m -p -2 -T -x ref=2:bframes=2:subme=5:me=umh
echo $DVD_NAME >> $BACKUPDIR/.movie_list.txt
cat $BACKUPDIR/.movie_list.txt | sort > $BACKUPDIR/Movie_List.txt
eject /mnt
fi