My Scripts

I'm a linux fan boy. I used Ubuntu exclusivly on my work computer at my last job, and loved it. On this page I'm posting scripts that I've written, that have been helpful to me. Now unless your a computer geek, these wont mean a thing, but I've put a lot of work into most of them, so I want to show them off.

Disclamer: I am not a programmer and most of what I've done here has been guided by that great well spring of human knowledge Google. That means, they work on my system but are not in any way guaranteed to work on yours. Security is non-existent. If they're helpful great, if not that's ok to. I accept no responsibility if for some reason things get hosed from using them.

Mounting Samba Shares (on a linux machine)

This script mounts all the shares I need from our samba server. Now I know you can do this automatically at start up, but I wanted to be able to easily mount and unmount them.

#!/bin/bash

LOGIN=$(zenity --entry --title="User Name" --text="Enter your login name:")
PASS=$(zenity --entry --title="Password" --text="Enter your password:" --hide-text)
mount.cifs //ipaddress of server/share name /local mount point -orw,user=$LOGIN,password=$PASS

Zenity gives it a gui asking for your user name and password. You need to have smbfs installed in order for the mount.cifs command to work. Again all of this is on Ubuntu, I haven't a clue how it works on other distros.


Unmounting Samba Shares (also on a linux machine)

#!/bin/bash

umount.cifs /local mount point

This umounts the shares. It's nice because if I leave my computer I don't have to log out, I simply unmount the shares. If some one tries to remount them they need my username and password. One note, should you try and re-start or shut down your computer without unmounting the samba shares it will hang. You can run this script automatically at shut down and restart, but I'm not going to explain how to set that up here.


Camper Barcode Generator

#!/bin/bash

#This coverts all the returns from DOS to Unix
tr -d '\r' < input.csv > input.txt

#This sorts the list from Christie by cabin
sort -t',' -k 3,3 input.txt > tempsorted.txt

sed '/^$/d' tempsorted.txt > sorted.txt

#This puts the names (name) in a file and the amount (money) in a file
INPUT=sorted.txt
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read FirstName LastName Lodging AgeToday Dollars
do
echo "$FirstName $LastName" >> name.txt
echo "$Dollars" >> money.txt

done < $INPUT
IFS=$OLDIFS

#This grabs the correct number of barcodes and puts them in a text file
./barcode.sh
#This generates the actual html file that is printed
./html.sh
#Remove all the extra files once they're done being used
rm barcode.tmp barcode.txt money.txt money.tmp name.tmp name.txt sorted.txt tempsorted.txt input.txt

barcode.sh

#!/bin/bash

barcodelength=$(cat sorted.txt | wc -l)

head -n "$barcodelength" barcode > barcode.txt

sed '1,'$barcodelength'd' barcode > barcodetmp
cat barcodetmp > barcode
rm barcodetmp

html.sh

This one requires a bit of explination. We have recently gotten a POS system in our camp store. Some of our campers are pre-paying so we need a way to assign them "gift" cards. Our customer relations lady gives me a .csv file for each camp. I then take that file, run it through my script and out pops an html table, with barcodes, camper names and the amount they have pre-paid. This table can be printed, and scanned into our POS system. I've commented most of the thing, but I'm pretty sure if any of my college professors saw this they would flip.


Backup a Humhub site (running on a Ubuntu 16.04 server VPS)

#!/bin/sh

rm /share/local/list.txt
rsync -avze ssh user@website.com:/remote_server/backup/ /share/local/
find /share/local/* -mtime 5 >> /share/local/list.txt
xargs rm < /share/local/list.txt

This is a fairly standard rsync script. This is run from a QNAP NAS, which has a few command line quirks. For example most of the documentation I found used -mtime +5. That doesn't work on the QNAP. It uses -5 or 5. +5 does nothing. There are cleaner ways to remove the old files but I couldn't get those to work on the QNAP.