Social security for getting on a large amount Beat The Cycle Of Debt Beat The Cycle Of Debt for an approved in addition questions.

Restarting Apache kills script

Posted: June 12th, 2012 | Author: | Filed under: Linux, Tech | Tags: , , , , , , , , , , , , , , , , , , | No Comments »

Another pretty specific problem.  If you have a bash script or any script that you gave sufficient privileges in the sudoers file and want the apache process to run.  If apache starts the processes directly with nohup or disown, etc. when you restart apache all of those child processes die. The workaround/logic is this:

1. Call initial php file through the browser

2. That file uses PHP Exec to call another php file through the command line

3. The command line PHP file forks twice and then calls whatever command/script that will be independent of the apache process.


Thanks to Jacob Kiers for having the ONLY site to describe this issue on the internet.
His site is here.

Our example

First file: 

$name = $_POST[‘name’];
exec(‘php ‘ . EQ_APP_PATH . ‘/scripts/thread_start.php ‘ . $name);
Second file:


$name = $argv[1];
/* Fork once */

$pid = pcntl_fork();

if ($pid === -1) {
die(‘First fork failed!’);
} else if ($pid) { // if parent

/* Fork again (as session leader) */

posix_setsid(); // become session leader

$pid = pcntl_fork();

if ($pid === -1) {
die(‘Second fork failed!’);
} else if ($pid) { // if parent
exec(‘nohup sudo ‘ . dirname(__FILE__) . ‘/ ‘ . $name . ‘ > /dev/null 2>&1 &’);

At the end of the above file, you call your script with nohup that will be independent of the apache process.
This way if you start the process with a webpage/apache, it will not die when apache is restarted or crashes.




Tomato Router Config – Backup Script

Posted: March 18th, 2011 | Author: | Filed under: Linux, Tech | Tags: , , , , , , , , , , | 2 Comments »

I recently was given the task to automate the backups of several remote routers that we manage that run tomato firmware.
Here is the Tomato developer’s site:
The main goals were:

  • To use https
  • To be automated (Cron)’d later
  • To scale from 1 to 1XXX routers

I tested it on Tomato Firmware 1.28 using my ASUS RT-N16 router, but it should work for any Tomato-firmware router.
There will be some slight modifications to run in cron, but let me know and I’ll be glad to help.
Download the .zip file here: tomatobackup1405

Extract the file so the full path will be /root/tomatobackup1405
Read the README inside the folder
chmod +x
Add your hosts to the tomatobackup1405_hosts.cfg file
Run it!

If successful, you will see a subfolder with the date YYYYMMDD and the file with CoName-tomato_v_.cfg
If there are connection problems, you’ll see an error message.

EDIT: There was a python rewrite by
Feel free to check it out here

Let me know if you have any thoughts or suggestions.

Appointment Reminder Calls – With Asterisk VoIP

Posted: July 21st, 2010 | Author: | Filed under: Asterisk VoIP, Linux, Tech | Tags: , , , , , , , , | 8 Comments »

A while back I had a meeting with a friend in Orlando, FL. He came up with the idea to provide an appointment reminder service to companies that would benefit from such a service. Doctor’s offices, Dentists, Mechanics, Repairmen, etc. I drew up the logistics of the program and began working on it in the fall of 2008. Since then we have had customers use the software to easily call their customers and remind them of appointments and also use the software for call blasting. Call blasting is a feature to call an unlimited amount of numbers and playback a message. Since I have experience in the Asterisk VoIP platform I programmed the system to allow for options and the customer to enter in input with their keypad.

The purpose of this article is to detail the logistics and share it with the Asterisk community.

Basic overview:
There are a few different ways to originate calls with Asterisk.
-From the Asterisk CLI directly with the “originate” command
-From the AMI (Asterisk Manager Interface)
-From .call files placed in /var/spool/asterisk/outgoing

I went with .call files because of a few reasons:
-I can generate all of the call files ahead of time because they are read based on the timestamp of the file (less load)
-It is straightforward and easy to follow, and also leaves behind the .call file that is archived after the call is finished
-Asterisk will parse and execute based on timestamp, so to burst 100 calls would require much less overhead than through AMI/CLI

There are some negative effects to the .call files too:
-Changes made need to remove and add another .call file (If the customer changes their appointment time after the file was generated)
-The lowest interval to generate calls is every minute, so we can burst to 400 calls/minute (also more difficult to throttle calls)

Now you know how the calls are originating on the system, let’s move on to the database and interface.
I hired someone to program the interface in AJAX and PHP. That way it is secure and saved a lot of time if I were to attempt it myself. The interface is very clean and easy to use for customers. They also have the ability to import 1,000 records at a time via CSV files. Feel free to demo the interface via the link on for “Demo the Interface”.
The interface stores the call data in MySQL which is then scanned hourly to process and create all of the .call files according to their timestamp. We only care about the calls that will be made by the system in the next hour, so those are the only .call files that are generated. The script is a PHP script that connects to the database with the query of calls to be made, strips them down, then does a loop to create the .call file, set the timestamp based on the variable, then move the .call file to /var/spool/asterisk/outgoing.

The .call files include 1 custom variable that is comma-delimited so we can parse out the appointment time, AM/PM, and any other custom variables.
The other important lines in the .call file point to the context in the Asterisk dialplan that the customer’s announcement and options are defined.

Now you may ask yourself, It will be a pain to manually add customer’s options and dialplan for every sign up, right? It was at first, but I created several automated scripts to generate the dialplan for the customer and “dialplan reload” when complete.

The rest of the accounting/etc is accomplished via bash cleanup scripts that write to the database and provide reporting/etc.
The same system can be used for call-blasting to a large group of number for a survey, snow day announcement, marketing message.

Please let me know if you have any questions or advice/constructive-criticism for me regarding the program.
And feel free to try out the demo interface and hear a reminder call!


Remote Access to Linux without forwarding ports

Posted: January 10th, 2010 | Author: | Filed under: Linux, Tech | Tags: , , , , , , | 2 Comments »

There have been many situations that I would like to have remote access to a Linux server, but I don’t have administration rights to the network the server resides on.
A few situations I’ve run in to:
1. A friend has a server and wants you to take a quick look (but no ports forwarded)
2. Customer has a server that you need to look at, but no remote access
3. You are working locally on a server but need to leave and access it later from another location

1. You need to have a publicly accessible Linux server with an SSH account (please don’t use root for this!)
2. Add a dumb user that has shell access but nothing else, don’t run any applications as this user (used for SSH only)

So in the case where you are physically at the server and need to get to it later, type:
ssh -N -f -R 19999:localhost:22 sshuser@

The options make it so after you authenticate with the password the shell goes to the background. needs to be replaced with your IP/Domain of the server you control
sshuser needs to be replaced with the dumb SSH user you setup earlier

Now when you get home, ssh to your server. Then use the Remote forwarding to get back to the original server:
ssh -p19999 sshuser@
You should now be on your remote server.
If you want to kill the connection, on your public server type:
ps -ef | grep ssh

Then you can:
kill -9

Remember when I said that you must create a dumb user earlier? This is in case you are in the situation where you must give the command to someone over email and have them execute it for you. That way you aren’t handing over root-level access to your server…ever.

2010 – No More Ads…Resolutions

Posted: January 4th, 2010 | Author: | Filed under: Asterisk VoIP, Linux, Mac, Tech | Tags: , , , , | No Comments »

I decided to start off 2010 with a few changes:
1. Choose a new theme for the site…done

2. Remove Ads…done(With the exception of the sweet animation my buddy did)

3. I’m studying AGI scripting with Asterisk and want to share my findings along the way. I hope to have a lot of posts soon for you guys.

4. I hope to have bi-monthly updates to the site at a minimum. Topics include but are not limited to: Asterisk, AGI, PHP, Linux, and anything else I find interesting. 2010 is going to be the year of knowledge.

5. I put a link on the right column, and I’m only going to say it once. If you want to buy me a beer, or contribute to my escapades with a small donation. Then I will smile knowing that someone appreciated the info enough to help me out.

Safe1405 – Automated or Interactive Asterisk backup solution -with auto FTP upload

Posted: April 27th, 2009 | Author: | Filed under: Asterisk VoIP, Linux, Tech, Uncategorized | Tags: , , , , , , , , , , , , , , , , , , , , , , , , , | 6 Comments »


Safe1405 is a bash script that will backup the popular Asterisk directories and place them in a tar.gz file. The script can be used in 1 of 2 modes.
The first mode is interactive, with a menu to choose:

  • Backup Everything (/etc/asterisk, Voicemail, Recordings, Sounds)
  • Just VM
  • Just Recordings
  • Just Sounds

After the file is created, it will prompt to upload to a remote FTP server.

The second mode is silent, and is best suited for automated execution via cron or at.
Just enable the UNATTENDED and PUT_FTP variables by setting them to “1”.  You can directly edit the paths to each directory if yours are non-standard.

The script can be directly downloaded here: Safe1405 Download Link


# Safe1405
# Author: Gregg Hansen -
# Safely tar and gzip Asterisk files

# Version 1.0 20090427
#-Backs up all important Asterisk files - Tar/Gz
#-Choose the file name, or Date by default
#-GUI-like. Able to be silent for cron, or interactive

#EDIT the below ABSOLUTE paths to match your directory structure:

#Date Var
FILEDATE="$(date +%Y%m%d)"
#Your ServerName
#Filename is FILEDATE-SERVERNAME.tar.gz

#Enable unattended mode/Remote FTP put (useful for Cron):
# Backup of /etc/asterisk ONLY (default)
# 1 = On, 0 = Off

#FTP Credentials

###--START CODE---###

### Interactive Mode Functions ###
cat <<EOF

Safe1405 Backup

1) Everything
2) /etc/asterisk
3) Voicemail
4) Recordings
5) Sounds
Q) Quit


echo -n "Prompt> "
read INPUT
case $INPUT in
1) everything;;
2) etc-ast;;
3) vm;;
4) recordings;;
5) sounds;;
q) exit;;
Q) exit;;

tar cfvz $FILENAME $VM
tar cfvz $FILENAME $MON
echo -en "Upload $FILENAME to FTP? (y or n) "
read INPUT
if [ "$INPUT" == "y" ]; then

### Unattended Mode Functions ###
tar cfvz $FILEDATE-$SERVERNAME-ETC-AST.tar.gz $ETC_AST ##Uncomment##$VM #$MON #$VAR_LIB

ftp -ivn <<EOF
open $FTP_IP

#### Start Program Flow ###
#Unattended Function Call(s)
if [ "$UNATTENDED" == "1" ]; then
if [ "$PUT_FTP" == "1" ]; then
#Interactive Function Calls

###–END CODE—###
Leave a comment if you have questions/suggestions or would like help setting up the script.