Tricontahedral Solitudinarian

The name doesn't really mean anything

It Starts With a Shebang

Posted by Doug on May 22, 2010

# I decided to try my hand at writing a simple shell script.  One click on a specific icon on my top panel in Ubuntu, and my novel is compressed (currently, from about 479.5 KB to 108 KB), and that compressed file is saved to two different locations, one on my primary hard drive, the other on my storage hard drive.  It is rather simple, but it serves its purpose well enough.  Here it is:

#!/bin/bash

# this script should compress a single file and then save it to both of my internal hard drives
# This is to preserve the novel I’m writing, hopefully against minor catastrophes

# this is the location and name of the file to be backed up
backup_file=“/media/hitagi-storage/Writing Projects/The Mecha Monogatari – Twilight of the Fierce God/The Mecha Monogatari – Twilight of the Fierce God [v2].doc”

# a shortened version of the name of the story file, for use in the backup file’s name
short_name=“TMM-TOTFG”

# the two places where the compressed file will end up
backup_destination_1=“/home/doug/Documents/TMM-TOTFG Backups”
backup_destination_2=“/media/hitagi-storage/Writing Projects/The Mecha Monogatari – Twilight of the Fierce God/Backups”

# generate a unique name for the compressed backup in the format, which should look something like “TMM-TOTFG-19-May-2010[20:33:12].tgz”
day=“$(date +%d)-$(date +%h)-$(date +%Y)”
time=“$(date +%T)”
archive_file=$short_name$day[$time].tgz”

# this line would get the name of my computer for use as part of the name for the compressed backup file, but I decided against using it
# hostname=$(hostname -s)

# these echoes were used for testing and have no function in the final script
# echo “$hostname”
# echo “$backup_file”
# echo “$short_name”
# echo “$archive_file”
# echo “$backup_destination_1”
# echo “$backup_destination_2”

# this one compresses the file and puts it in the first backup location
tar czf $backup_destination_1/$archive_file” “$backup_file

# this one copies the backup to the second backup location
cp $backup_destination_1/$archive_file $backup_destination_2

# this puts a notification up on the screen saying it’s done
# requires libnotify-bin
notify-send “File $archive_file successfully created”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: