OP25 daytime and nighttime Whitelist

Status
Not open for further replies.

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
I would like to change my OP25 whitelist based on the time of day.
I'm running a single instance of OP25 in terminal mode launched with the command line:
Code:
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2


In the evenings, I change my whitelist to add more talkgroups and then stop/restart OP25 in the CLI .

What would be a good way to automate this? How can I change my whitelist and restart OP25 automatically?

For example, at a predefined time (say 9:00 p.m.), I would like to switch to my bigger whitelist for the evening hours and then return to my original whitelist again in the morning on a daily basis. My whitelist file name is
Code:
op25/op25/gr-op25_repeater/apps/white.lst

I guess my question is more of a Linux scripting how-to question than an OP25 question. Any help would be greatly appreciated! :)
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
make separate daytime & nighttime lists, separate non-racist file names. :ROFLMAO:

Symlinks are your friend here (ln -s ...) You can just change them twice a day and relaunch op25 to load whichever dataset you want.

cron entry at 2100 hrs for script to kill python instances running rx.py (pgrep / pkill can help you here, in case you don't want to blanket kill all python jobs and leave some running). Same script then changes the symlink to white.lst to point to nighttime.lst. Script then relaunches op25 with symlink loading the night time list, with the same command but different data.

You would also want a similar script in the morning to rotate back.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
Thanks for the reply! I'm a extreme newbie when in comes to Linux commands. I will read up on Crontab and Symlinks and try to make some smoke. ;)

make separate daytime & nighttime lists, separate non-racist file names. :ROFLMAO:

Symlinks are your friend here (ln -s ...) You can just change them twice a day and relaunch op25 to load whichever dataset you want.

cron entry at 2100 hrs for script to kill python instances running rx.py (pgrep / pkill can help you here, in case you don't want to blanket kill all python jobs and leave some running). Same script then changes the symlink to white.lst to point to nighttime.lst. Script then relaunches op25 with symlink loading the night time list, with the same command but different data.

You would also want a similar script in the morning to rotate back.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
Thanks for the reply! I'm a extreme newbie when in comes to Linux commands. I will read up on Crontab and Symlinks and try to make some smoke. ;)
symlinks are magic. As you are simply pointing the reference in (i assume) trunk.tsv to a different data source, you can change the configuration it is loading w/o actually editing/rewriting files. You are just making a link to a new config.


ln -s ./daytime.list ./white.list points white.list to daytime.list.
./rx.py ... with that in the trunk.tsv will run with the daytime list.

...some time later....

ln -s ./nighttime.list ./white.list points white.list to night time.list.
./rx.py ... with that in the trunk.tsv will run with the night time list.

make a little shell script for cron to run and you can automate this as much as you want.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
symlinks are magic. As you are simply pointing the reference in (i assume) trunk.tsv to a different data source, you can change the configuration it is loading w/o actually editing/rewriting files. You are just making a link to a new config.


ln -s ./daytime.list ./white.list points white.list to daytime.list.
./rx.py ... with that in the trunk.tsv will run with the daytime list.

...some time later....

ln -s ./nighttime.list ./white.list points white.list to night time.list.
./rx.py ... with that in the trunk.tsv will run with the night time list.

make a little shell script for cron to run and you can automate this as much as you want.

For my first whack at this, I created 4 files and tried to run the process manfully without cron.
The files are:
daytime.list
nighttime.list
startdaytime.sh
startnighttime.sh

When I run one of the .sh scripts for the first time a symlink is created in the apps directory and everything runs like it should. If I try to run a .sh script again I get an error:
Code:
~/Desktop/op25/op25/gr-op25_repeater/apps$ ./startnighttime.sh
ln: failed to create symbolic link './white.lst': File exists

Then OP25 starts without the updated white.lst

Here is the startdaytime.sh:

Code:
#! /bin/sh
pkill python
ln -s ./daytime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2

Here is the nighttime.list:

Code:
#! /bin/sh
pkill python
ln -s ./nighttime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
When I run one of the .sh scripts for the first time a symlink is created in the apps directory and everything runs like it should. If I try to run a .sh script again I get an error:
Code:
~/Desktop/op25/op25/gr-op25_repeater/apps$ ./startnighttime.sh
ln: failed to create symbolic link './white.lst': File exists


ln -sf adds the 'force' flag which overwrites existing.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
ln -sf adds the 'force' flag which overwrites existing.

That works!

Now I'm tiring to get my cron job set up.
For some reason I have to use sudo and password to view or edit my user cron.

As a test, I tried to get the script to run every 2 minutes so I could "see" it in action. OP25 was running is terminal as normal and at the 2 minute mark OP25 terminated. I don't know if I should expect a new terminal window to open on it's own or... ???
Here is my cron:

Code:
wxfreak@wxfreak-Satellite-L775D:~/Desktop/op25/op25/gr-op25_repeater/apps$ sudo crontab -u wxfreak -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
*/2 * * * * /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startdaytime.sh

Sorry If I'm not using the proper terminology or syntax. You are awesome! Thanks so much!
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
Now I'm tiring to get my cron job set up.
For some reason I have to use sudo and password to view or edit my user cron.
This is normal, this prevents you from nuking your system from orbit without a tad bit of oversight. sudo can be neutered a bit if you'd like. You can edit the sudoers file to make your username a bit more powerful, and a little less naggy if desired.

As a test, I tried to get the script to run every 2 minutes so I could "see" it in action. OP25 was running is terminal as normal and at the 2 minute mark OP25 terminated. I don't know if I should expect a new terminal window to open on it's own or... ???
Code:
wxfreak@wxfreak-Satellite-L775D:~/Desktop/op25/op25/gr-op25_repeater/apps$ sudo crontab -u wxfreak -l
<snip>
*/2 * * * * /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startdaytime.sh

try this.

Code:
*/2 * * * * /bin/bash /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startdaytime.sh

this tells cron to launch a new shell, and pass your shell script as an argument and run it.

You can even set up logging to tell you if it switched back and forth, and any errors if you'd like.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
try this.

Code:
*/2 * * * * /bin/bash /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startdaytime.sh

this tells cron to launch a new shell, and pass your shell script as an argument and run it.

You can even set up logging to tell you if it switched back and forth, and any errors if you'd like.

Tried the above, OP25 was running normally at the 2 minute mark the program terminated leaving the terminal window open and the flowing:
Code:
wxfreak@wxfreak-Satellite-L775D:~/Desktop/op25/op25/gr-op25_repeater/apps$ ./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.003.000-0-unknown

If it helps any? I get this prompt when trying to run either the startdaytime.sh or startnightime.sh manually. I have to pick 'Run in Terminal' .

Screenshot at 2021-05-22 19-16-39.png
 
Last edited:

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
Tried the above, OP25 was running normally at the 2 minute mark the program terminated leaving the terminal window open and the flowing:
Code:
wxfreak@wxfreak-Satellite-L775D:~/Desktop/op25/op25/gr-op25_repeater/apps$ ./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.003.000-0-unknown
2 minutes, you say? :unsure:


Code:
#! /bin/sh
pkill python 
ln -s ./daytime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2

It's doing exactly what you're telling it to do...every two minutes. Every two minutes cron is running a script and the first line after the shebang is to pkill python. ;)

As for that window, it's clear you are using gnome...I eschew gnome, for reasons like this. Gnome (or most 'simple' window managers) tries to think for the user in some instances, and in this case it's saying "hey, do you want to run or edit this text file" just in case you didn't do what it thought you wanted it to. I suppose you could fiddle with file extention assignments and default actions and eliminate that prompt, but considering how often you will be doing that, i'd get away from it.

I always run my shell scripts from a shell/terminal like ./startdaytime.sh. If it's an interactive process that you're going to be starting intermittently, that's fine...this is something you are automating, so starting it from a prompt would be preferential. This allows you to see how it will be running if you weren't there clicking on it in a window.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
It's doing exactly what you're telling it to do...every two minutes. Every two minutes cron is running a script and the first line after the shebang is to pkill python. ;)

Yes true, true... :) but how can I restart OP25 after killing it? I was hoping
Code:
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
would restart op25 in a visible terminal window? Do I need to have a command to press the enter key? How may I check a log of what is happening? Sorry about the newbie questions, the carrot is dangling in front of me and and trying to understand. I appreciate your patience!
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
Yes true, true... :) but how can I restart OP25 after killing it?
I think this is a bit of red herring. Your script is killing your current running instance of python, thussly op25. If you run it via the command line, with cron not trying to run it every 2 minutes, does op25 stay running? I'm not sure why you think you are having trouble regarding your aforementioned 2 minute interval other than that.

as for logging, you are already redirecting stderr of op25 (the '2>') to a file. Errors will show up in there. If you are looking to log what your bash script is doing, that will involve different logging.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
If you run it via the command line, with cron not trying to run it every 2 minutes, does op25 stay running?

Yes it will stay running.
I was under the impression if the whitelist changes while OP25 is running, I would need to kill and restart OP25 for the whitelist changes to take effect, but I might be wrong about that?
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
In the stderr.2 log I'm getting

Code:
terminal: exception:
Traceback (most recent call last):
  File "/home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/terminal.py", line 461, in run
    self.setup_curses()
  File "/home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/terminal.py", line 78, in setup_curses
    self.stdscr = curses.initscr()
  File "/usr/lib/python2.7/curses/__init__.py", line 33, in initscr
    fd=_sys.__stdout__.fileno())
error: setupterm: could not find terminal

Listening on 127.0.0.1:23456
python version detected: 2.7.12 (default, Oct  8 2019, 14:14:10)
[GCC 5.4.0 20160609]
Flowgraph completed. Exiting
 

boatbod

Member
Joined
Mar 3, 2007
Messages
3,410
Location
Talbot Co, MD
Yes true, true... :) but how can I restart OP25 after killing it? I was hoping
Code:
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
would restart op25 in a visible terminal window? Do I need to have a command to press the enter key? How may I check a log of what is happening? Sorry about the newbie questions, the carrot is dangling in front of me and and trying to understand. I appreciate your patience!
If you are going to programmatically restart op25 from a script (e.g. crontab) I would recommend using the http terminal option so that op25 itself does not have to be running in a visible window. That way you can kill and restart to your heart's content and the terminal will continue to be accssible via a browser.

Moreover, you may wish to set up op25 to run under systemd control then you can just issue the command "sudo systemctl restart op25-rx" when you want it to stop and restart. The op25-rx.service file is a template for how to do this.

Yes it will stay running.
I was under the impression if the whitelist changes while OP25 is running, I would need to kill and restart OP25 for the whitelist changes to take effect, but I might be wrong about that?

It is possible to reload the blacklist/whitelist dynamically from the op25 terminal window using the "R" command.
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
If you are going to programmatically restart op25 from a script (e.g. crontab) I would recommend using the http terminal option so that op25 itself does not have to be running in a visible window. That way you can kill and restart to your heart's content and the terminal will continue to be accssible via a browser.

I am just looking for the best way to change the whitelist automatically on a daily schedule.
I have changed OP25 to run in the http terminal.
How do I set up a schedule kill and restart from this point?
Thanks!
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
BTW my script currently looks like this but I'm willing change or scrap anything at this point to make it clean and easy. :)
Code:
#! /bin/sh
cd /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps
pkill -f rx.py
ln -sf ./nighttime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2
 

AB5ID

Member
Joined
Aug 6, 2007
Messages
799
Location
Lee's Summit, MO (Kansas City)
I seem to have something that is working, please let me know if I should change anything.

startdaytime.sh is:
Code:
#! /bin/sh
cd /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/
pkill -f rx.py
ln -sf ./daytime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2 -l http:127.0.0.1:8080

startnighttime.sh is:
Code:
#! /bin/sh
cd /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps
pkill -f rx.py
ln -sf ./nighttime.list ./white.lst
./rx.py --args 'rtl' -N 'LNA:47' -S 1000000 -o 25000 -T trunk.tsv -V -w -2 -U 2>stderr.2 --crypt-behavior 2 -l http:127.0.0.1:8080

crontab is:

Code:
0 23 * * * /bin/bash /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startnighttime.sh
0 6 * * * /bin/bash /home/wxfreak/Desktop/op25/op25/gr-op25_repeater/apps/startdaytime.sh
 
Status
Not open for further replies.
Top