User Tools

Site Tools


workshops:byo_scripts

BYO Scripts

We talked about many different scripts and scripting languages.

Our verdict
C - Not a scripting language but Bob uses it for everything and loves it.
Ruby - Great language
Python - Closely follows
Perl - Minimal lines of code, messy looking language
Bash - Can be restricting and hard to read

Here are some of the scripts we covered:

Michael Pope's Backup Scripts

Michael Pope's Backup scripts
To run my scripts make sure you have ruby installed. If you are on a debian/Ubuntu based computer type:

$ sudo apt-get install ruby

Also make sure you modify the top of my scripts to backup the directories and devices relating to your computer.

backup-ltsp - Performs a 7 day rolling system and separate data backup using fsarchiver and tar with multi-core compression options. Full logging is enabled. This script is to be used in cron.

backup-chroot-ltsp - If you use LTSP1) then this maybe handy as it backs up your client image section.

Rob Moonen's Photo to HTML Scripts

Rob Moonen's Photo's to HTML scripts

First master a CD with your images, using the directory structure you want to use on the webpage, mine starts with /camera_type/Img0001 etc… You will have to change the relative path in photo2html_table.sh to reflect this.

Next change to your working html directory and prepare your thumbnails in there. Make your working directory path the same as the relative path on your CD except on your www/photo_album root. Next copy the files from the CD subdirectory in there. My CD directory structure is ${Camera_name}/IMG0001 etc… The document root is /var/lib/apache/htdocs/www/photos this directory contains the photos in a structure Nikon/Img0001 etc… With about 80 photos per directory, actually the same as on CD. ;-)

To prepare your images we use part of the imagemagick suite with this command:

$ mogrify -size 120x120 *.jpg -resize 120x120 +profile "*"

Now run the photo2html script thus: ../../photo2html/photo2html.sh assuming the script is also under document root of your photo album, if not substitute the installed path to it.

Document root of your photo album is Document root/photos

The path for $base in photo2html.sh will have to be changed according to the distribution used.

Finally, make sure you have a symbolic link to your /cdrom in the document root directory, mine is Nikon/cdrom.

Oh, and here is a nice little five liner to do off-site backups of parts of your system, run it as a cronjob in /etc/cron.daily but root will need to be using public key authentication so that there won't be a password requirement.

#! /bin/bash
enum=`date +%F`
tar -czf /tmp/backup$enum.tgz /home/mint /etc/X11/xorg.conf /etc/crontab /etc/cron.daily /root/.ssh /var/cache/apt/archives --totals
scp -B /tmp/backup$enum.tgz robert@ares:/var/www/ares/mint
rm -rf /tmp/backup$enum.tgz
exit 0

And here is the script to delete old backups:

#!/bin/bash
COUNT=0
for file in `ls -c /var/www/ares/mint`
do
  COUNT=`expr $COUNT + 1`
  # If we have 8 backups, delete the last, so we only keep a weeks worth, deleting the oldest
  if [ 0$COUNT -eq 8 ]
  then
    rm /var/www/ares/mint/$file
    COUNT=`expr $COUNT - 1`
  fi
done
exit 0

Run this script on your webserver. Of course I could have just used find with the -exec option utilising rm, but I wanted to use bash. ;-)

1)
Linux Terminal Server Project
workshops/byo_scripts.txt · Last modified: 2017/10/12 21:58 by 127.0.0.1