Choices and Acountability: Anarchic bash scripting

Setting Priorities from a Dog’s Point of View: A Dog Script

So, i’ve invested a little bit of time in getting this program up and running. It has been a nice introduction to some of the structures in bash programming, and the fun thing about bash programming is that you can debug your lines of code on the fly by running them in the shell. The headache is obviously with the quirkiness of getting quotes to pass and execute commands. This code is not fun to debug, and as you can see from the teed output (setup5.bsh | tee setup5.output), i still haven’t figured out how to evaluate the minutes expression (I just know someone is going to post a 2 command synthetic equivalent:-)). Anyway, I wanted to post this in a secure place, so that I can retrieve it virus free when I want to. Obviously, it isn’t to difficult to edit the event_array to pray, play games, etc.
Future goals:
1) Get backup working, eventually layered with options.
General idea: Looking at file system over the last week (since the last backup), extracting and comparing the current filesystem with the old iso’s, I’ve mapped out those areas that have changed, and separated within this area those areas that are personal from those areas that are system. Probably, these different sections will have different backup priorities. I still want everything to fit on 2 CDs, so:
CD1 (mostly invariant) will have:

usr.iso (/usr) and
exec_lib.iso (/lib /bin /srv /sbin) on it.

CD2 (mostly variant) will have:

persional.iso (/root and /home) and
var_sys.iso (/media /sys /boot /opt /tmp /proc /var) on it.

Pseudocode with commands for most complete backup:
1. check for existing isos of last backup in defined directories. Otherwise output a listing of what’s in the directories in case its tared or compressed old filesystem.
2. if iso’s don’t exist in these directories, make them appear.
3. check for disk space.
4. individually mount each iso onto /var, and extract archive into /backup/oldbackup.
5. compare current file system with archive. Save differences into a log file.
6. At this point a decision has to be made, if usually invariant files have changed for no apparent reason, what changed (is the iso in the archive good?). Load old hard archive into /var, and compare hard iso with file system backup iso. Backup current file system of invariant files, as well as old soft archive onto new hard CD2 (note this in log file) and, although not necessarily by default better, make the decision to reinstall system from original disks (thereby forcing the hacker to repeat or physically replace original system media). We will call this “checking and resolving system catastrophe.”
7. If this passes, move onto personal level.
extract old personal.iso
mk or find directory /trash
Note files that are different.
Interactively prompt to save or trash files, placing the desired files in either /backup or /trash. Schedule rm /trash. Could also shred, but nothing I do is that confidential – so, 95% open out, but only really smart or hopefully nice invited, in. If I were working with things that I was worried were going to be stolen, I might change this.
8. tar and compress files but not dir in /backup (leave /old/backup alone).
9. mkisofs and then burn CD.
10. Check CD by mounting ISO onto /var, extracting and comparing. If pass, delete files in /backup/oldbackup/backup3/personal and mv /backup/personal.iso into /backup/oldbackup/backup3/personal/personal.iso
2) Implement choice of scheduling events.
3) Output a daily log file.

Some useful links:
getting started in bash programming

CODE:setup5.bsh

#!/bin/bash
#
#
#
#
#
#
event_array=(“nothing” “walking dogs” “work” “workout” “clean up” “pay bills” “backup system”)
num_events=7
date
echo “Today is a brand new day. How would you like to start?”
echo ” ”
echo ” ”
echo ” ”
echo “Please enter numbers in the order you would like to proceed separated”
echo “by spaces. Simply enter 0 to ignore.”
echo ” ”
echo ” ”
echo ” ”
i=1
while [ $i -lt 7 ]
do
echo “$i. ${event_array[$i]}.”
i=$(( $i + 1 ))
done
echo ” ”
echo ” ”
echo “Choices?”
read choice
echo ” ”
echo “You chose to proceed in the following order: $choice”
echo ” ”
echo ” ”
for i in ${choice}
do
echo “${event_array[$i]}”
done
count=””
for i in ${choice}
do
finished=””
eventbgn=””
echo ” ”
echo ” ”
echo “${event_array[$i]]} anticipated.”
echo “Describe your activity. ”
read description
echo “Please press enter when you begin your activity.”
read bgn
date
# eventbgn=$(expr $(”date | awk ‘{print $4}”’|sed “s/:.*//”)*60+
# expr $(”date | awk ‘{print $4}”’|sed “s/^..:\(..\).*/\1/”))”
eventbgn=”$(expr $(”date | awk ‘{print $4}”’|sed “s/:.*//”)*60+
expr $(”date | awk ‘{print $4}”’|sed “s/^..:\(..\).*/\1/”))”
# echo $eventbgn
echo “Please press enter when you have finished to ${event_array[$i]]}.”
read finished
while [ -n “$finished” ];
do
break
done
date

eventend=”$(expr $(”date | awk ‘{print $4}”’|sed “s/:.*//”)*60+
expr $(”date | awk ‘{print $4}”’|sed “s/^..:\(..\).*/\1/”))”
echo
echo “You spent ($eventend “-” $eventbgn) minutes to $description ”
echo “thereby accomplishing your ${event_array[$i]]} activity.”
count=$(expr $((count+1)))
echo -n $count “. ”
case “$i” in
1)
echo “Dog Walk done. Your dogs say: I love you.”
;;
2)
echo “Work done. Relax.”
;;
3)
echo “Work out done. Your body says thank you for caring!”
;;
4)
echo “Clean up done. Good job!!!!!”
;;
5)
echo “Pay bills done. Ouch!”
;;
6)
echo “Backup system done. Find a blank CD.”
;;
esac
done
#
#

sample output: setup5.out
Mon Jul 25 21:23:15 MDT 2011
Today is a brand new day. How would you like to start?

Please enter numbers in the order you would like to proceed separated
by spaces. Simply enter 0 to ignore.

1. walking dogs.
2. work.
3. workout.
4. clean up.
5. pay bills.
6. backup system.

Choices?

You chose to proceed in the following order: 1 3 5 4 2 6

walking dogs
workout
pay bills
clean up
work
backup system

walking dogs anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:23:41 MDT 2011
Please press enter when you have finished to walking dogs.
Mon Jul 25 21:23:53 MDT 2011

You spent (21*60+
23 – 21*60+
23) minutes to do 10 sits and 10 downs at dog park
thereby accomplishing your walking dogs activity.
1 . Dog Walk done. Your dogs say: I love you.

workout anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:24:06 MDT 2011
Please press enter when you have finished to workout.
Mon Jul 25 21:24:10 MDT 2011

You spent (21*60+
24 – 21*60+
24) minutes to 50 situps
thereby accomplishing your workout activity.
2 . Work out done. Your body says thank you for caring!

pay bills anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:24:43 MDT 2011
Please press enter when you have finished to pay bills.
Mon Jul 25 21:24:46 MDT 2011

You spent (21*60+
24 – 21*60+
24) minutes to get and mail money order for ebay RAM
thereby accomplishing your pay bills activity.
3 . Pay bills. Ouch!

clean up anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:25:13 MDT 2011
Please press enter when you have finished to clean up.
Mon Jul 25 21:25:15 MDT 2011

You spent (21*60+
25 – 21*60+
25) minutes to clean kitchen counter
thereby accomplishing your clean up activity.
4 . Clean up done. Good job!!!!!

work anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:25:28 MDT 2011
Please press enter when you have finished to work.
Mon Jul 25 21:25:30 MDT 2011

You spent (21*60+
25 – 21*60+
25) minutes to read papers
thereby accomplishing your work activity.
5 . Work done. Relax.

backup system anticipated.
Describe your activity.
Please press enter when you begin your activity.
Mon Jul 25 21:25:46 MDT 2011
Please press enter when you have finished to backup system.
Mon Jul 25 21:25:47 MDT 2011

You spent (21*60+
25 – 21*60+
25) minutes to write code for this.
thereby accomplishing your backup system activity.
6 . Backup system. Find a blank CD.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

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