Archive for the ‘ Linux ’ Category

Asterisk Voicemail Check Disk Usage Script

This latest script was written to prevent 3:00am phone calls. I was recently called because our voicemail server was beginning to run out of disk space. The following script simply scans the voicemail directory, if a user is over 100MB it looks up their extension in the asterisk database and then sends them an email notification to clean it out. Below is the script:

#!/bin/bash
 
#set the maximum disk usage for a user to approx 100MB
size_limit=100000
 
function send_email () {
 
    subject="Voicemail Over Limit"
    message="/tmp/emailmessage.txt.$f"
 
    echo "Hello $name, " > $message
    echo " " >> $message
    echo "This is a notification that your voicemail is currently over the allowed limit.  You are currently using $humansize.  Please either manually delete the voicemails, or you can send an email to patb@codero.com for help with wiping all of the new and saved voicemails in your mailbox." >> $message
    echo " " >> $message
    echo "Thank you," >> $message
    echo "Admin" >> $message
 
    /bin/mail -s "$subject" "$email" < $message
}
 
for f in $(ls /var/spool/asterisk/voicemail/default/)
do
  size=$(du -s /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
  if [ "$size" -gt "$size_limit" ]
    then
 
        humansize=$(du -sh /var/spool/asterisk/voicemail/default/$f | awk '{print $1}')
        #Query the database for the users email address
        email=$(mysql -u asterisk --password=dbpassword asterisk -e "select email from voicemail_users where mailbox = '$f'")
        #Parse just the email address out of the above query
        email=$(echo $email | awk '{print $2}' )
 
        name=$(mysql -u asterisk --password=dbpassword asterisk -e "select fullname from voicemail_users where mailbox = '$f'")
        name=$(echo $name | awk '{print $2,$3}' )
        #echo "$name    $f  $email  $humansize"
        send_email $email $name $humansize
  fi
    # take action on each file. $f store current file name
done

Debian/Ubuntu Anti-Virus and Root Kit Scan Script

A customer requested this script, once I started working on it I realized how useful this could be. I have this setup on a weekly CRON task. The script is very simple, it updates ClamAV and RKHunter then scans the server with both and mails the results to the specified email address. If you plan on adding this script to your server, you might want to ensure that you have the correct versions of ClamAV and RKHunter.

Click here to download the script

Click Here to see the full post with install instructions

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!

Use NMAP To Detect Conficker

I found this gem of an Nmap command yesterday. I was unable to write about this nifty command because my site was offline. But I’m back now!

Important Notes:

You will need to download the latest version of nmap from insecure.org, or you can click here

The command:

nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 [targetnetworks]

Just remove [targetnetworks] and replace that value with the subnet you wish to scan. Since my gateway is 192.168.1.1, I altered the command to scan my network to look like the following:

nmap -PN -T4 -p139,445 -n -v --script=smb-check-vulns --script-args safe=1 192.168.1.*

Analyze the output:

A clean machine should report at the bottom: “Conficker: Likely CLEAN”, while likely infected machines say: “Conficker: Likely INFECTED”. For more advice, see this nmap-dev post by Brandon Enright.

SSI Test Script

Often, when supporting dedicated servers, we need to check if Server Side Includes are working correctly. We wrote this very simple script that we upload on to our customers servers as test.shtml. Here’s the script:

 
<!--#echo var="DATE_LOCAL" -->

If you do not see the date displayed when browsing to your test.shtml file, check your httpd.conf file and ensure that mod_include is enabled. Restart Apache and test again, you should see the current date on the server.

How To Add Additional FTP Users to a Domain in Plesk

This guide will show you how to create a separate FTP login for a specific domain using Plesk. This gives two different users the ability to connect to the same directory with the same permissions.

Click Here to see the full guide.

Asterisk Rick Roll Script

You know Rick Astley will never give you up, let your friends know. This was my first Asterisk Scripting project, decided to post the end results under the Asterisk header at the top of the page. Check it out, and let your friends and loved ones know that you’ll never give them up. Click here to check it out

Auto Ban Brute Force Attempts

This script was just handed to me by a friend, every sever with SSH access should have this script installed. This script will automatically ban an IP address that fails to authenticate after 3 attempts. You can change the ban duration with a simple command line option.

Click Here to check it out.