This is possible using the walletnotify parameter in your bitcoin.conf file.
walletnotify=/home/bitcoin/transaction.sh %s
This will call transaction.sh script with txid as a parameter. From there, you can basically do something.
For instance:
#!/bin/sh curl -d "txid=$1" http://127.0.0.1/callback
Note: The address you want to control must be part of your wallet.
source share