Posts Tagged ‘ Bash

Dump Asterisk Realtime Voicemail users into Voicemail.conf

While I’ve been lazy about updating my site, I have not been lazy with writing new scripts and coming up with ideas to write about.

The first in the set that I’m going to make public is a script to dump your Asterisk Realtime Voicemail database users into a flat voicemail.conf file. I used this technique while troubleshooting to revert back to the standard setup while I was working on the realtime config.

#!/bin/bash
function get_mailbox {
 
   mailbox=$( mysql -u dbuser --password=dbpass asterisk -e "select mailbox from voicemail_users where uniqueid = '$i'")
   mailbox=`echo $mailbox | awk '{print $2}'`
 
}
 
function get_password {
 
    password=$(mysql -u dbuser --password=dbpass asterisk -e "select password from voicemail_users where uniqueid = '$i'")
    password=`echo $password | awk '{print $2}'`
 
}
 
function get_fullname {
 
    name=$(mysql -u dbuser --password=dbpass asterisk -e "select fullname from voicemail_users where uniqueid = '$i'")
    name=`echo $name | awk '{print $2}'`
 
}
 
function get_email {
 
    email=$(mysql -u dbuser --password=dbpass asterisk -e "select email from voicemail_users where uniqueid = '$i'")
    email=`echo $email | awk '{print $2}'`
 
}
 
function write_file {
 
    echo "$mailbox => $password,$name,$email,,attach=yes|saycid=no|envelope=no|delete=no" >> /root/test_dump.txt
 
}
 
for (( i=1; i<=151; i++))
do
get_mailbox
get_password
get_fullname
get_email
write_file
done

Debian/Apache2 Virtualized Host Script

I wrote this script so that I could quickly create virtualized subdomains on my server. I wrote it so that all you have to do to reuse it is simply change the first 3 lines of the file to match your server. This is version 1.o and I plan to add some more error handling and improvements further down the road. Feel free to contact me with any feedback or suggestions.

Click Here to see the full Post
or
Click Here to download the script

Random Futurama Quote From Shell

Random Futurama Quotes to fill the day. I just found this awesome site: http://commandlinefu.com. There are a lot of great ideas on this site, I recommend you take a few minutes and check it out. Major props to icco of commandlinefu.com:

Just issue the following command:

curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2

Here’s the sample output:

[burnsforce.com ~]# curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
Fry: Robots don't go to heaven.

I’d like to integrate this into the /etc/motd file, so everytime I connect to my server via SSH I get a new quote. I have a few ideas but haven’t gotten around to implementing them yet. If you have any suggestions, I’d love to hear them!

Arduino Server/Service Monitor

I’ve successfully written a bash script that runs once every minute. The script detects whether or not my server is online by issuing a simple ping request. Based on results of the ping request(s), the arduino will display a green LED when the server is online or a red LED if the server is offline. I’ve also setup a cron job to execute the script once a minute, giving me up to the minute status of my server. This specific project is not terribly amazing, but the foundation for many more projects to come has laid.

Click Here for the full project page

Plesk Hack: Email and FTP Usernames and Passwords

I wrote this simple script for work. This script allows us to gather all the username and password information on the server to let us troubleshoot faster. This is an early version of the script, I plan on added more functionality to improve the speed of troubleshooting. This script was not intended for malicious purposes, please do not use it for such.

Edit: It looks like a few people out there have been publishing my code without attribution.  I really don’t mind if you post my code, but please give me credit.  The one I’ve found didn’t even change the header (with my full name in it) of the script or the “doneskies” at the end.  Have some class and give me proper attribution.

Click Here to see the script