[arm-allstar] Setting up auto connection using cron

Doug Crompton wa3dsp at gmail.com
Tue Apr 4 23:07:32 EST 2017


Justin,

 This can be done in rpt.conf but I prefer to do it externally. There are
actually examples in the /etc/asterisk/local directory.

You can learn some Linux doing this. Here are the steps. This looks long
but is really simple.

Login to your Pi and select the shell - ADMIN menu 9

cd /etc/asterisk/local

Create this script in /etc/asterisk/local

nano connect.sh

Enter the following two lines.... use *73 instead of *3 for permanent
connect

#!/bin/bash

/usr/bin/asterisk -rx "rpt fun $1 *3$2"

Save it

Then create a disconnect script.

nano disconnect.sh

​Then enter the following two lines. Again *71 instead of *1 for a
permanent disconnect.

#!/bin/bash

/usr/bin/asterisk -rx "rpt fun $1 *1$2" ​

​Save it...

Now make them both executable.

chmod 750 connect.sh
cdmod 750 disconnect.sh

What these do.  The $1,2, etc. substitute parameters from the command line
when you run the script. So if you typed this...

​
​
​/etc/asterisk/local/connect 40000 40001

it would connect your 40000 to node 40001. The first node has to be a node
on the server you are running the script on.  Asterisk -rx "command string"
simple executes what you would type at the client prompt.​


​You can (and should to test) run these manually at the command line as
shown above substituting your from and to nodes.

Now automating. This is easy but you need to understand cron the Linux
timing system to run jobs. It is best to Google cron. It consists of timing
parameters followed by when is suppose to run when those parameters are met.

So using the connect and disconnect scripts here is how you would make a
script. Lets suppose you want to connect node 40000 to node 40001 at 9AM
and disconnect at 10PM. All times are 24 hours in cron.

To edit the cron table do:

crontab -e

This puts you in the nano editor. You will see previous lines there. DO NOT
alter them. cursor down to a blank line and enter your new line(s).

00 09 * * * /etc/asterisk/local/connect.sh 40000 40001

This says connect at 0900 (9AM - Minutes first then hours) node 40000 to
node 40001

Now we can enter our disconnect line.

00 22 * * * /etc/asterisk/local/disconnect.sh 40000 40001

This says disconnect at 2200 (10PM) node 40000 from 40001

Of course all of this is example to show how you make scripts and how you
would run them at specific times.

The cron entries designated by * if not used (spaces between them) are:

​

*minute hour dom month dow *
DOW - day of week is 0 Sunday to 6 Saturday.

So in the above example a cron entry like this:

15 20 * * 1  some_command

would execute the command at 8:15PM on Monday.

You can modify the scripts as you see fit. For instance if you want to
specify the full command in the cron you could make a script called
command.sh

It could look like this:

#!/bin/bash

/usr/bin/asterisk -rx "rpt fun $1 $2"

the the cron would look like this -

00 09 * * * /etc/asterisk/local/connect.sh 40000 *340001

​Experiment - its fun!​



*73 Doug*

*WA3DSP*

*http://www.crompton.com/hamradio <http://www.crompton.com/hamradio>*

On Tue, Apr 4, 2017 at 10:59 PM, "Justin Reed via arm-allstar" <
arm-allstar at hamvoip.org> wrote:

> Group,
> I'm looking into what it takes to setup a node so that it makes a
> connection at a certain time and then disconnects at a certain time.
> For example my node 45754 would connect to 1754 (a pseudo node on the same
> Pi) at 8pm and then drops at 9pm.
> I believe this is done within rpt.conf but I haven't figured out exactly
> what to do.
>
> Thanks,
> Justin
> NV8Q
>
> _______________________________________________
>
> arm-allstar mailing list
> arm-allstar at hamvoip.org
> http://lists.hamvoip.org/cgi-bin/mailman/listinfo/arm-allstar
>
> Visit the BBB and RPi2/3 web page - http://hamvoip.org
>
>


More information about the arm-allstar mailing list