Archief

Berichten met tag ‘bash’

SMS to Twitter

31 maart 2010 Reacties uit

I’ve wrote this shell script that uses an SMS to post to Twitter. It is ment to be used as an Eventhander for SMS Server Tools, but it’s simple enough for stand alone usage with simple text files.

If used as an Eventhandler the arguments are “RECEIVED” and the path to the SMS file, add “eventhandler=/path/to/sms2twitter.sh” to your smsd.conf. Without SMS Server Tools you can also use a simple file for posting to twitter:
Create a file starting like this:

  1. Phone: 0634567890
  2.  
  3. Your tweet in max. 140 characters

Then call this script with the path to your file:

  1. sms2twitter.sh /path/to/file.txt

You will need to create a sqlite3 DB with this schema:

  1. sqlite3 sms2twitter.db \
  2.     "CREATE TABLE account (phone, username, password, PRIMARY KEY(phone))"

For every Phone that you allow to post Tweets thru SMS you need to run:

  1. sqlite3 sms2twitter.db \
  2.     "INSERT INTO account VALUES (‘phonenumber’, ‘username’, ‘password’)"

Lees meer…

Categorie├źn:Linux Tips & Trics Tags:, , ,

KDE dialog for crypysetup

1 oktober 2007 Reacties uit

Here is a bash script that uses kdialog to present a password prompt and tries to mount a crypt device. It interacts with the (k)ubuntu “cryptsetup” package.

  1.  
  2. #!/bin/bash
  3. if [ -r /lib/cryptsetup/cryptdisks.functions ]; then
  4.   . /lib/cryptsetup/cryptdisks.functions
  5. else
  6.   kdialog –title $(basename $0) –error "/lib/cryptsetup/cryptdisks.functions not found"
  7.   exit 1
  8. fi
  9.  
  10. crypt_create (){
  11.   DLG_TITLE="Cryptsetup Dialog"
  12.   mountpoint=$(grep $MAPPER/$1 /etc/fstab | awk ‘{FS=" "}{print $2}’)
  13.   sudo cryptsetup status $1 > /dev/null
  14.   if [ $? -ne 0 ]; then
  15.     pwd=$(kdialog –title "$DLG_TITLE" –password "mapping $1 to device <$2>
  16.  
  17. Enter passphrase:")
  18.     if [ $? -ne 0 ]; then return 3; fi
  19.     if [ "$pwd" == "" ]; then
  20.       kdialog –title "$DLG_TITLE" –warningyesno "empty password, try again?" && {
  21.         crypt_create $1 $2
  22.         return 2
  23.       }
  24.     fi
  25.     echo "$pwd" | sudo cryptsetup create $1 $2
  26.     mount $mountpoint 2&>/dev/null|| {
  27.       sudo cryptsetup remove $1
  28.       kdialog –title "$DLG_TITLE" –warningyesno "cryptsetup create <$1> <$2> failed, try again?" && {
  29.         crypt_create $1 $2
  30.         return 2
  31.       }
  32.       return 0
  33.     }
  34.   else
  35.     if [ -z $3 ]; then
  36.       kdialog –yesno "$MAPPER/$CRYPT_NAME is active, do you want to deactivate?" && {
  37.         umount $mountpoint
  38.         sudo cryptsetup remove $1
  39.       }
  40.     fi
  41.   fi
  42.   return 1 #cryptdevice already setup
  43. }
  44.  
  45. if [ -r $TABFILE ]; then
  46.   grep -Ev "^#" $TABFILE | while read line; do
  47.     cryptname=$(echo $line | awk ‘{print $1}’)
  48.     cryptdevice=$(echo $line | awk ‘{print $2}’)
  49.     crypt_create $cryptname $cryptdevice $1
  50.   done
  51.   exit 0
  52. else
  53.   kdialog –title $(basename $0) –error "$TABFILE not readable"
  54.   exit 2
  55. fi
  56.  
Categorie├źn:Linux Tips & Trics Tags:, , ,