Tagged: BASH Toggle Comment Threads | Keyboard Shortcuts

  • Akarsh Simha 6:32 am on December 17, 2007 Permalink
    Tags: BASH, mail merge   

    Mail Merge 

    I remember long back, during school, we had to learn this thing called ‘Mail merge’ in Wordstar or something like that. (I remember mugging those wordstar shortcut keys like C-k b, C-k k to mark blocks and crazy stuff like that) I felt it was a great thing to be able to mass mail people and still make it sound very friendly:

    Dear Mr. <n00b-who-got-fooled-by-mailmerge>

    I was in a similar situation when I needed to send out BAS Web-Privy Members’ accounts (like http://members.bas.org.in/kstar for instance). So this is what I did – I had the members’ names, ftp logins, passwords blah blah blah and their email address in a ‘:’ separated list in a file, where I saved the details as and when I created the accounts. Then, I typed some e-mail format that went like

    Dear NAME,

    Your account has been created, your login name is FTPAC and password is FTPPASS

    b lah blah blah

    Then, I wrote this tiny, ugly bash script that did it. It’s highly inefficient and I’d love to hear ways to do this more efficiently. Here it is. Basically uses awk on each line of the file listing the account details (‘webmem’ as I’ve called it) to retrieve the info into variables and then uses sed on the email format to replace all those “NAME” and “FTPAC” stuff by their corresponding values. Finally, pipes it into mail to send it to the account holder.

  • Akarsh Simha 7:24 pm on December 15, 2007 Permalink
    Tags: AWK, BASH, GNOKII, Mass SMS   

    The power of a GNU-empowered terminal 

    My father needed some help. The task at hand was to send invitation SMSes to about 200 mobile phone numbers.

    The mobile numbers were in a text file like an address book with several irrelevant fields. The mobile numbers were stored in the form of ‘Mobile:<number>\n’ . We wanted only the mobile numbers, so I did a

    cat <phonebookfile> | grep Mobile

    and there – all the phone numbers were separated. Next, I wanted to throw away the Mobile: part and retain only the number. That was done using awk:

    cat <phonebookfile> | grep Mobile | awk “BEGIN{ FS = ‘:’ } { print $2 } > listofnumbers

    Next, we wanted to send an SMS to each of these numbers. I typed the SMS into some file (call it smsfile) and then connected my mobile phone to the computer and then did a

    for i in `cat listofnumbers`; do cat smsfile | gnokii –sendsms $i >> gnokii-out 2>> gnokii-error; echo $i >> finishednos; done;

    And that’s it! We had some trouble inbetween, and sending failed starting from the Nth number in the file. So what we repeated the command with tail -n <num> instead of cat on listofnumbers, to send it to the remaining.

    That’s the power of BASH + GNU on the command line.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc