Bash Script – Test Veeam Linux Agent Socket and Restart Service if Needed

I recently started using the full version of Veeam Backup & Replication (Build 11.01.1261) in a corporate production environment and was kind of shocked to find that the Veeam Agent for Linux (Agent version: 5.0.1.4493) fails so regularly with the following warning and error messages:

Processing ServerName Error: Failed to execute agent management command print. Connection refused Failed to connect: /var/tmp/veeam/socket/veeamservice.sock. Failed to connect to veeamservice daemon.

and

Task failed. Error: Failed to execute agent management command print. Connection refused Failed to connect: /var/tmp/veeam/socket/veeamservice.sock. Failed to connect to veeamservice daemon.

Apparently, Veeam offers no error checking or resolution process for automatically restarting the service, so I had to write a quick script to resolve this ongoing issue.
Continue reading “Bash Script – Test Veeam Linux Agent Socket and Restart Service if Needed”

Ubuntu – Icecast2 Startup Script with Ices2 Support

Recently I set up an Icecast server to be able to stream music on hold to my Asterisk servers at work. Here is an updated init script for Icecast2 that adds support to start the Ices2 source client at the same time. For streaming audio from a playlist with Ogg support, Ices2 is a good candidate. For streaming audio from an mp3 based playlist, have a look at Ices0 that can be downloaded on the same site. There is also an array of different Icecast source clients to choose from here. This just happened to be the first one that I tried out. I ended up bastardizing the code somewhat to make it conform to my own personal preferences by using functions and what not to make it all pretty like. I also chose to run Ices2 as the same user as the icecast user, so you would have to update any permissions on the Ices2 directories and config files as needed.
Continue reading “Ubuntu – Icecast2 Startup Script with Ices2 Support”

Linux – Force Remote Reboot of System

I ran into a problem yesterday where I could SSH into a remote machine but a majority of the bash commands weren’t working and were giving an “Input/ouput error”, including the shutdown command. Upon further inspection, this particular machine, which was a thin client with 128 MB of flash storage, had run out of drive space. The suggestion on this stack exchange article worked perfectly so I just wanted to document it here for my own future reference.

As long as you have root access, you can run the following command to force a system reboot: Continue reading “Linux – Force Remote Reboot of System”

Bash Script – Log Concurrent Asterisk Calls to MySQL and Other Useful One-Liners

Here is a quick and dirty bash script I threw together today to log the concurrent calls for each of my long distance trunks in Asterisk to a MySQL database to be able to quickly analyze usage trends. Sure there is probably other open-source software out there that can do this and give pretty little graphs and what not (cdr-stats or maybe queue metrics come to mind), but where’s the fun in that? As I mentioned, the script is extremely primitive (just the bare minimum as I didn’t have much time to spend on it) and contains no error checking whatsoever but it could also be used as a pretty handy one-liner in bash.

Show all active SIP Calls on a single trunk

asterisk -x "core show channels verbose" | grep "^SIP/yourSIPTrunkName-"

Show concurrent number of SIP Calls on a single trunk

asterisk -x "core show channels verbose" | grep -c "^SIP/yourSIPTrunkName-"

Show all active DAHDI calls on channels 1-24
Continue reading “Bash Script – Log Concurrent Asterisk Calls to MySQL and Other Useful One-Liners”

Bash Script – Convert a Batch of WAV Files to SLINEAR Format for Asterisk Hold Music

Here are a couple of useful one-liners that I picked up from voip-info.org a while back to manipulate a bunch of audio files in a single directory with Sox. You can save yourself some processing power on your Asterisk PBX if all of your hold music is in SLINEAR format that way no transcoding has to take place.
Continue reading “Bash Script – Convert a Batch of WAV Files to SLINEAR Format for Asterisk Hold Music”

Bash Script – An Alternative to Logrotate.d for Asterisk Log Files

For the longest time, I was having trouble getting the log rotate daemon to work properly with Asterisk. I tried using both postrotate and prerotate options on Ubuntu Server and no matter what, I always ended up with dozens or even hundreds of files if I wasn’t keeping a close eye on them. I never figured out why or wanted to spend a ton of time searching for answers but for some reason, the numbering on the log files would always get messed up and it would start adding extra periods on the end of the filenames and everything would get all out of whack.
Continue reading “Bash Script – An Alternative to Logrotate.d for Asterisk Log Files”

Bash Script – Pcapsipdump Spool Directory File Rotation – OR – Rotate Directories Based on YYYYMMDD Format

In the config file for the pcapsipdump program, there is a retention option where you are supposed to be able to enter the number of days to keep the directories in your spool folder and it should auto purge out the old directories/files, however, this option either doesn’t appear to be implemented yet or doesn’t work if you run the app as a different user (could be a permissions issue maybe?).

Anyhow, this script is my solution to the problem. It could also very easily be modified and used where someone needs to search and delete directories that are based on YYYYMMDD format with the ability to whitelist or ignore certain directories, hence the alternate title. Yet another alternate title could even be “Bash Script Functions – Convert YYYYMMDD to Unix Time and Vice Versa” but obviously the script would need modified a little because it has been tailored to fit my needs.

When run as a cron job, the script will grab both the spool directory and the retention period from the pcapsipdump config file and will purge out any old folders based on YYYYMMDD format so they aren’t eating up all your valuable disk space.

I also added a couple of noteworthy user-configurable options. The first being a directory whitelist feature (IGNORE_DIRS array), this option can be used in situations where there are directories that you don’t want purged or would like to keep the data indefinitely and that can also be used in conjunction with the PURGE_ALL feature to delete out any subdirectories that aren’t specifically listed in the whitelist if you are a clean freak.

Download it now – pcaprotate.sh

#!/bin/bash
#
# pcapsipdump file rotation
# By Nathan Thomas
# 12/05/2014
#

### VARS ###
# Location of the pcapsipdump config file
CONF_FILE='/etc/default/pcapsipdump';

# Keep the spool folder clean - Delete all folders (except those in the ignored directories array)
# yes - Keep the spool folder free from any directories not in the ignore list
# no - Don't worry about any other random folders in the spool directory
 Continue reading "Bash Script – Pcapsipdump Spool Directory File Rotation – OR – Rotate Directories Based on YYYYMMDD Format"

Bash Script – Sync a File to an Array of Hosts

#!/bin/bash
# Sync a file to a remote set of servers using scp and check using diff
# NOTE: This requires the use of 'sshpass' and IS insecure in nature
# It also assumes the user credentials are identical on all hosts
# and that they have the necessary permissions on the remote directory
# Author: Nathan Thomas
LOGFILE='/var/log/sync_files.log'
SSH_USER='non-root-user'
SSH_PASS='password'
CONF_FILE='/etc/appdir/myconfig.conf'
SERVERS=('server1.fqdn.com' 'server2.fqdn.com' 'server3.fqdn.com')
for HOST in "${SERVERS[@]}" ; do
        # NOTE: This won't work if the host keys are not already in the ssh cache
        # Flush ssh hosts - Either uncomment these two lines on first run or you could leave it uncommented for hosts that change addresses a lot
 Continue reading "Bash Script – Sync a File to an Array of Hosts"