Monday, 9.50pm
Sheffield, U.K.
If you have any trouble sounding condescending, find a Unix user to show you how it’s done. – Scott Adams
Sometimes I feel like much of what I write is too theoretical.
It’s all very well exploring ideas but what are you actually doing?
As Jay Abraham writes, people don’t need strategies. They need solutions.
The world is full of solutions – some of them very complex and many of them solve problems that have been solved before.
Take a simple thing – managing a database.
A database, in its simplest form is like a box of index cards.
Each card is a record and you write stuff on it.
Now, you can get very excited about big, complex databases but in the Unix world a text file can be a database where you use a line for each record.
Interestingly, I strugged to find any applications that would let me create a simple personal database that I could use – for example to maintain a contact database or customer relationship management (CRM) tool.
Odd, I thought.
Back when I was young, my dad let me help him create a database for a medical conference. I can remember showing the visiting doctors their data on the screen and checking if it was right.
This was on an old IBM PC/XT using some version of dBase, I imagine.
Anyway… you wouldn’t believe how hard it is to find something that lets you manage a text file as a simple database – that lets you do the basic operations: create, read, update and delete on the files.
Now, of course you can just open the file and edit away, but that’s no fun.
So today’s diversion was to create a small crm. That’s a bit like taking time off from chopping down a tree to work on sharpening the axe.
If you’re being generous, that is.
On the other hand, it’s possibly a complete waste of time, implementing something widely available in a way no one else might ever use.
But here’s the thing.
I’ve found the Internet and the stuff other people have put out there immensely useful in all the work I do.
So, maybe sharing this bit of code, unfinished as it is, may be useful to you as well. Apologies for the formatting – tired of struggling with WordPress!
Cheers,
Karthik Suresh
#!/bin/bash # Script to manage a simple crm # It's going to be as terse as ed crmfile=$1 # Setup file if [ ! -f $crmfile ]; then echo "Name:Company:Phone:Email:Next Action" > $crmfile fi while [ "$command" != "q" ] do read command case $command in q) exit 0 ;; h) echo "Commands" echo "q: exit" echo "a: add record" echo "r: show records" echo "e: edit record" echo "d: delete record" ;; a) echo "Full name:" read fullname echo "Company:" read company echo "Phone:" read phone echo "email:" read email echo "Next action:" read nextaction echo "Write to file? (y/n)" read confirm if [ "$confirm" = y ]; then echo $fullname":"$company":"$phone":"$email":"$nextaction >> $crmfile fi ;; r) cat $crmfile | column -s":" -t | less -NS ;; d) echo "Line to delete?" read line sed -i -e $line"d" $crmfile ;; e) echo "Line to edit?" read line sed -n -e 1,$line"p" $crmfile | column -s":" -t str=$(sed -n -e $line"p" $crmfile) IFS=":" read -r -a NAMES <<< "$str" fullname=${NAMES[0]} company=${NAMES[1]} phone=${NAMES[2]} email=${NAMES[3]} nextaction=${NAMES[4]} #echo $fullname $company $phone $email $nextaction echo "Press enter to keep existing values" echo "Full name:" read value if [ "$value" != "" ]; then fullname="$value" fi echo "Company:" read value if [ "$value" != "" ]; then company=$value fi echo "Phone:" read value if [ "$value" != "" ]; then phone=$value fi echo "email:" read value if [ "$value" != "" ]; then email=$value fi echo "Next action:" read value if [ "$value" != "" ]; then nextaction=$value fi echo "Write to file? (y/n)" read confirm string=$fullname":"$company":"$phone":"$email":"$nextaction echo "Current entry" if [ "$confirm" = y ]; then ed - $crmfile <<EOF $line c $string . w q EOF fi echo "Record changed. Press r to show" ;; esac done