Bash Thumbnailer Script with Imagemagick

A while ago, I was working on creating a script to create thumbnails of all the pictures I had taken so I could put them up on my personal site for family/friends to view. It started out as a very basic script but as I developed my website, I found new ways to display the photos. Namely using css for the image to come up double sized by mousing over on the picture. Well this created quite a challenge to put all the code for my pictures in the HTML. So I went a step further and adjusted the script to create the php necessary for the galleries. The way I create all my pages is to use a standard header and footer file and include them into my individual pages. So I then changed the script so it created a full blown page ready to be used. The script is below. You may have to modify it slightly for your own needs, but it should work fine. The main requirement is the imagemagick software. In Slackware it is included with the default install. With your own distro you may need to add it yourself.

[code=’bash’]
#!/bin/bash

echo “Resizing Pictures and Creating PHP”
mkdir thumbs previews view
cp ../rhine-river/view.php .
cp ../rhine-river/download.php .

totalcount=0
currentcount=0

if [ $1 = y ]
then
name=$2
picnum=0
for i in *.jpg *.JPG; do

picnum=$(($picnum + 1))

pic=`echo $i | awk -F . ‘{print $1}’`
rename=”${name}-`printf “%03d” $picnum`.jpg”
mv “$i” $rename

done
fi

for i in *.jpg; do

totalcount=$(($totalcount + 1))

done

echo “There are $totalcount pictures to convert.”

# Create the header
echo \<\?php > index.php
echo \$pagetitle \= \”Insert Title Here\”\; >> index.php
echo include_once\(\”../../includes/header.php\”\)\; >> index.php
echo ?\> >> index.php
echo \Page Description Here\ >> index.php
echo \

OpenDNS Dynamic IP Update Script through Linux

I recently read a blog post on the How-To Geek about setting up OpenDNS and the options it gives you to secure your internet browsing. They have quite a few filtering options including Phishing sites, along with blocking adult-related sites, and about 50 other categories along with a fully redundant DNS nameserver resolving. I decided to try it and set it up on my home network. The problem is that if you have an internet provider that provides you with a dynamic IP (IP address changes occasionally, if you aren’t sure what you have you probably have a dynamic address), you need to update the IP with OpenDNS. They have a lot of clients out there to do it, but as far as I found there were no linux clients. So I created a short linux script to do just that.

[lang=’bash’]#!/bin/bash

# Copyright (C) 2006 Jeremy Brent Hansen
#
# These are for your OpenDNS username and password. At this time, I do
# not know how to hide this info, so you will need to make sure you have the
# correct file permissions.
username=your_opendns_username
passwd=your_opendns_password

# This is where the log file will be stored. Currently it only logs the current IP
# and the response back from OpenDNS. The log will keep one backup. I
# just used a folder in my home directory (make sure the folder exists).
log_dir=~/.opendns

# Revolves the log file. Keeps one backup.
mv $log_dir/log $log_dir/log.1

while [ 1 ]
do

date >> $log_dir/log
/usr/bin/curl -i -m 60 -k -u $username:$passwd ‘https://updates.opendns.com/account/ddns.php?’ -silent >> $log_dir/log
echo -e “\n” >> $log_dir/log

# Resends the info after 5 minutes. Eventually I plan on changing it,

# so it only updates when your IP changes.
sleep 600

done[/lang]

So, there you have it. No root permissions are required, so I just have it in my .profile for my normal user. Just run it with the & at the end, so it will background the process.