Cron Jobs

Post your tips and tricks here
w1tcc
Posts: 4
Joined: Sun May 31, 2020 8:39 pm

Cron Jobs

Post by w1tcc » Fri Jul 03, 2020 9:09 pm

Cron jobs in V4.1.2 are working well now that Andy has added all the scripts necessary to connect in all the modes.
The simplest d-star example would be to go to the telnet console and type in:
sudo pistar-link ref030_c
to unlink type: sudo pistar-link unlink
for YSF it's: sudo pistar-ysflink ysf21080
for BM it's: sudo pistar-bmapi addtg 3100 0
for TGIF it's: sudo pistar-tgifapi link 31665 0

Type in the script name alone to see what all the options are.
Other modes are available such as NXDN and P25.

Automatically connecting to weekly nets makes these command line options useful. First backup your pistar config and if possible your SD card just in case. Next go to the pistar dashboard -> Configuration -> Expert -> System Cron What you will see is the existing system wide cron job. After the last line which currently ends with "/etc/cron.monthly" add and edit the following:

Code: Select all

# Connect to BM 3100 default timeslot at 16:15 then delete at 16:20 on Friday the 5 day of the week
# The hash is a comment within the file.  Command line start with: MIN HOUR DOM MON DOW USER COMMAND
15 16 * * 5   root  pistar-bmapi    addtg 3100 0
20 16 * * 5   root  pistar-bmapi    deltg 3100 0
Followed by a CR then press -> Apply Changes Go back to the admin dashboard to watch and listen.

Next is another example for auto starting a Net at 10pm eastern local time

Code: Select all

#Nebraska D-Star Net on Thurs.
00 22 * * 4   root pistar-link        ref073_c 
59 22 * * 4   root pistar-link        unlink
Third example:

Code: Select all

#Test America link on YSF Sunday night 8pm for 15 min
00 20 * * 0   root pistar-ysflink     ysf21080  
15 20 * * 0   root pistar-ysflink     unlink
For duplex hotspots BM and TGIF the timeslot will be 1 or 2 not 0 and the connections will be static.
Have fun
Tim C

VK2FMET
Posts: 72
Joined: Fri Dec 20, 2019 1:19 am

Re: Cron Jobs

Post by VK2FMET » Mon Sep 07, 2020 1:15 am

Code: Select all

[email protected](ro):~$ sudo pistar-bmapi addtg 31012 0
 Request to BrandMesiter API: Add TG 31012 to TimeSlot 0 for DMR ID 5050766            
Traceback (most recent call last):                                                     
  File "<string>", line 1, in <module>                                                 
  File "/usr/lib/python3.7/json/__init__.py", line 296, in load                        
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)          
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads                       
    return _default_decoder.decode(s)                                                  
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode                       
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())                                  
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode                   
    raise JSONDecodeError("Expecting value", s, err.value) from None                   
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)                
Answer from BrandMesiter API:                                                          
                                                                                       
[email protected](ro):~$ sudo pistar-tgifapi link 31665 0                                
 Request to TGIF API: Set TimeSlot 0 to TG 31665 for DMR ID                            
Answer from TGIF API: Somthing went wrong with this request                            
                                                                                       
[email protected](ro):~$ sudo pistar-tgifapi link 31665 2                                
 Request to TGIF API: Set TimeSlot 2 to TG 31665 for DMR ID                            
Answer from TGIF API: Somthing went wrong with this request                            
                                                                                       
[email protected](ro):~$ 
Can you give me a hint as to what's wrong here?
Alan
VK2FMET

KE7FNS
Posts: 948
Joined: Wed Apr 17, 2019 11:11 pm

Re: Cron Jobs

Post by KE7FNS » Mon Sep 07, 2020 2:05 am

VK2FMET wrote:
Mon Sep 07, 2020 1:15 am
Can you give me a hint as to what's wrong here?

Do you have a BM API key installed and can you see the BM manager in the ADMIN section of the dashboard?

If yes then run updates and upgrades until it says theres nothing left to do.

If that doesn't fix it, you'll need to reimage and restore from a backup.

Also, I'd set an ESSID while you are at it, it isn't assigning one from the code you pasted. You should have a 9 digit DMR ID when you have an ESSID assigned.
If someones previous actions are any indication of their future actions, then I predict the deletion and removal of access will happen at any moment. 7-11-2020.

"07/13/20 This Website Has Been Taken Down" ... again :lol:

VK2FMET
Posts: 72
Joined: Fri Dec 20, 2019 1:19 am

Re: Cron Jobs

Post by VK2FMET » Mon Sep 07, 2020 3:34 am

OK - to answer:
Q1: The error is this exception: raise JSONDecodeError("Expecting value", s, err.value) from None
and the TG does not connect.
Q2: Yes I do have a key installed and I do see the Manager on teh dashboard.
Q3: I run my HS 24/7 it's 4.1.2 Dashboard 20200813 but I have just done update and upgrade and nothing was updated/upgraded - it says nothing to update and I am already running latest version.

What will re-image do since I am on the latest?

My other identical (except it's DStar/YSF and not DMR) hotspot does work fine with the command line -ysflink and -link commands for ysf and dstar reflectors.
Alan
VK2FMET

VK2FMET
Posts: 72
Joined: Fri Dec 20, 2019 1:19 am

Re: Cron Jobs

Post by VK2FMET » Mon Sep 07, 2020 3:39 am

OK - why do I need to set an ESSID when I have one radio, one DMR hotspot?
Alan
VK2FMET

KE7FNS
Posts: 948
Joined: Wed Apr 17, 2019 11:11 pm

Re: Cron Jobs

Post by KE7FNS » Mon Sep 07, 2020 4:34 am

VK2FMET wrote:
Mon Sep 07, 2020 3:34 am
OK - to answer:
Q1: The error is this exception: raise JSONDecodeError("Expecting value", s, err.value) from None
and the TG does not connect.
Yeah, I see where the error was reported at. Not sure why you are repeating it.
VK2FMET wrote:
Mon Sep 07, 2020 3:34 am
What will re-image do since I am on the latest?
A re-image will replace any corrupted files that are on your system. Just from what I can see there appears to be some issue when it is trying to execute those python scripts. So something must of corrupted those python scripts that are part of the python installation.

I was hoping that an update might of pulled new copies of the scripts in question, but that doesn't appear to be the case. So you are out of luck.

It would just be simpler and faster for you to backup and re-image, than it would be for me to try to explain to you how you can fix it.
VK2FMET wrote:
Mon Sep 07, 2020 3:34 am
My other identical (except it's DStar/YSF and not DMR) hotspot does work fine with the command line -ysflink and -link commands for ysf and dstar reflectors.
Those commands are not the same, so theres no relation. They don't use a BM API key either.
VK2FMET wrote:
Mon Sep 07, 2020 3:39 am
OK - why do I need to set an ESSID when I have one radio, one DMR hotspot?
I didn't say you NEEDED one, I said I would assign one, even if I only had one hotspot. When I used that command it reported my DMR ID as a 9 digit number.
If someones previous actions are any indication of their future actions, then I predict the deletion and removal of access will happen at any moment. 7-11-2020.

"07/13/20 This Website Has Been Taken Down" ... again :lol:

KE7FNS
Posts: 948
Joined: Wed Apr 17, 2019 11:11 pm

Re: Cron Jobs

Post by KE7FNS » Mon Sep 07, 2020 4:39 am

Oh, you could possibly try

Code: Select all

sudo pistar-update
from the command line (SSH) that might pull a python update from the repo and maybe fix it.

I always forget that regular users always use the dashboard links to update and those don't do the OS updates. I always use the CLI and never use the dashboard for anything.
If someones previous actions are any indication of their future actions, then I predict the deletion and removal of access will happen at any moment. 7-11-2020.

"07/13/20 This Website Has Been Taken Down" ... again :lol:

AF6VN
Posts: 466
Joined: Fri Jul 20, 2018 1:15 am

Re: Cron Jobs

Post by AF6VN » Mon Sep 07, 2020 4:32 pm

KE7FNS wrote:
Mon Sep 07, 2020 2:05 am
VK2FMET wrote:
Mon Sep 07, 2020 1:15 am
Can you give me a hint as to what's wrong here?
Do you have a BM API key installed and can you see the BM manager in the ADMIN section of the dashboard?
Given that the script checks for the (a) key before parsing the command options, and isn't issuing

Code: Select all

else
        echo "Unable to find your BrandMesiter API Key, no API commands available."
        exit 0
I'd conclude there is /something/ stored as the API key.

{I'm more amazed at the many mis-spelled "BrandMeister" in these messages!}

This mess, however, ...

Code: Select all

RESULT=$(wget -q -O - --user-agent="Pi-Star cli tool for: ${DMRID}" --header="Content-Type: application/x-www-form-urlencoded" --header="Authorization: Basic ${APIKeyB64}:"  --post-data="${APIDATA}" "${APIURL}" | \
        python3 -c "import sys, json; print(json.load(sys.stdin)['message'])")
echo "Answer from BrandMesiter API: ${RESULT}"
... appears to run a Python instance with everything provided as a single command line, taking the output from wget piped into stdin, loading it as JSON, and extracting the "message" field which gets sent to stdout. I'm not skilled in Linux shell scripts -- that seems to imply that the stdout from Python is getting fed back to the RESULT variable. There isn't much that can go wrong with that python invocation.

The TGIF API is just looking for an HTTP status code

Code: Select all

RESULT=$(wget -q -O - --user-agent="Pi-Star cli tool for: ${DMRID}" --header="Content-Type: application/x-www-form-urlencoded" "${APIURL}")
if [[ ${RESULT} == 200 ]]; then
        RESULT="OK"
else
        RESULT="Somthing went wrong with this request"
fi
echo "Answer from TGIF API: ${RESULT}"
echo ""
exit 0
Might be worth removing/commenting out the |\ and python3 lines, and seeing what the raw return data looks like. And maybe see what the command line is returning for apikey and dmrid (yes, two undocumented commands)

Code: Select all

[email protected](ro):~$ sudo pistar-bmapi apikey
Your BrandMeister API Key is: ***suppressed***
[email protected](ro):~$ sudo pistar-bmapi dmrid
Your DMR ID is: 1126104
[email protected](ro):~$ sudo pistar-bmapi addtg 3100 0
 Request to BrandMesiter API: Add TG 3100 to TimeSlot 0 for DMR ID 1126104
Answer from BrandMesiter API: Talkgroup 3100 added on slot 0.

[email protected](ro):~$ sudo pistar-bmapi deltg 3100 0
 Request to BrandMesiter API: Delete TG 3100 from TimeSlot 0 for DMR ID 1126104
Answer from BrandMesiter API: Talkgroup 3100 remove from slot 0.


--
AF6VN
Dennis L Bieber

KE7FNS
Posts: 948
Joined: Wed Apr 17, 2019 11:11 pm

Re: Cron Jobs

Post by KE7FNS » Mon Sep 07, 2020 8:02 pm

AF6VN wrote:
Mon Sep 07, 2020 4:32 pm
Given that the script checks for the (a) key before parsing the command options, and isn't issuing
I didn't devote any time digging into the actual bmapi script written by Andy at all. I just looked at the error codes and noticed that they are not a script related to Pi-star at all. They are scripts that belong to the python installation itself.

I just thought that maybe he was trying to do something and didn't have the API key populated.

AF6VN wrote:
Mon Sep 07, 2020 4:32 pm
{I'm more amazed at the many mis-spelled "BrandMeister" in these messages!}
I misspell it all the time, thank google for spell checking.
AF6VN wrote:
Mon Sep 07, 2020 4:32 pm
This mess, however, ...

Code: Select all

RESULT=$(wget -q -O - --user-agent="Pi-Star cli tool for: ${DMRID}" --header="Content-Type: application/x-www-form-urlencoded" --header="Authorization: Basic ${APIKeyB64}:"  --post-data="${APIDATA}" "${APIURL}" | \
        python3 -c "import sys, json; print(json.load(sys.stdin)['message'])")
echo "Answer from BrandMesiter API: ${RESULT}"
... appears to run a Python instance with everything provided as a single command line, taking the output from wget piped into stdin, loading it as JSON, and extracting the "message" field which gets sent to stdout. I'm not skilled in Linux shell scripts -- that seems to imply that the stdout from Python is getting fed back to the RESULT variable. There isn't much that can go wrong with that python invocation.
[/code]
I'm pretty sure the failure is at the

Code: Select all

import sys, json;
It appears there is something wrong with his json scripts in the python installation (/usr/lib/python3.7/json/__init__.py) as those are not anything modified or maintained by Andy. There should be no reason those scripts are failing.

AF6VN wrote:
Mon Sep 07, 2020 4:32 pm
The TGIF API is just looking for an HTTP status code

Code: Select all

RESULT=$(wget -q -O - --user-agent="Pi-Star cli tool for: ${DMRID}" --header="Content-Type: application/x-www-form-urlencoded" "${APIURL}")
if [[ ${RESULT} == 200 ]]; then
        RESULT="OK"
else
        RESULT="Somthing went wrong with this request"
fi
echo "Answer from TGIF API: ${RESULT}"
echo ""
exit 0
I'm not sure how or why we got into TGIF.
AF6VN wrote:
Mon Sep 07, 2020 4:32 pm
Might be worth removing/commenting out the |\ and python3 lines, and seeing what the raw return data looks like. And maybe see what the command line is returning for apikey and dmrid (yes, two undocumented commands)

Code: Select all

[email protected](ro):~$ sudo pistar-bmapi apikey
Your BrandMeister API Key is: ***suppressed***
[email protected](ro):~$ sudo pistar-bmapi dmrid
Your DMR ID is: 1126104
[email protected](ro):~$ sudo pistar-bmapi addtg 3100 0
 Request to BrandMesiter API: Add TG 3100 to TimeSlot 0 for DMR ID 1126104
Answer from BrandMesiter API: Talkgroup 3100 added on slot 0.

[email protected](ro):~$ sudo pistar-bmapi deltg 3100 0
 Request to BrandMesiter API: Delete TG 3100 from TimeSlot 0 for DMR ID 1126104
Answer from BrandMesiter API: Talkgroup 3100 remove from slot 0.

Those undocumented commands were probably just Andy testing his script early on in development to make sure the API key was loading correctly, and the communication path to retrieve info like the DMR ID was working before attempting to dive into the addtg and delltg commands.

If it is what I think it is, his system will fail with the same error messages because it can't load the scripts it needs properly.

Thats why I suggested he just reimage and start over with a fresh image that will work out of the box. I've already spent more time typing this one post up than the time it would take for him to reimage. Its just the easier route to get back to a fully working hotspot.
If someones previous actions are any indication of their future actions, then I predict the deletion and removal of access will happen at any moment. 7-11-2020.

"07/13/20 This Website Has Been Taken Down" ... again :lol:

AF6VN
Posts: 466
Joined: Fri Jul 20, 2018 1:15 am

Re: Cron Jobs

Post by AF6VN » Tue Sep 08, 2020 1:14 pm

KE7FNS wrote:
Mon Sep 07, 2020 8:02 pm
I didn't devote any time digging into the actual bmapi script written by Andy at all. I just looked at the error codes and noticed that they are not a script related to Pi-star at all. They are scripts that belong to the python installation itself.
The imported modules are standard Python library routines.
I'm pretty sure the failure is at the

Code: Select all

import sys, json;
It appears there is something wrong with his json scripts in the python installation (/usr/lib/python3.7/json/__init__.py) as those are not anything modified or maintained by Andy. There should be no reason those scripts are failing.
The error message indicates that what is being /read/ from sys.stdin does not match what is expected for JSON format.

Code: Select all

  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode                       
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())                                  
  File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode                   
    raise JSONDecodeError("Expecting value", s, err.value) from None                   
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)  

Code: Select all

    def raw_decode(self, s, idx=0):
        """Decode a JSON document from ``s`` (a ``str`` beginning with
        a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.

        """
        try:
            obj, end = self.scan_once(s, idx)
        except StopIteration as err:
            raise JSONDecodeError("Expecting value", s, err.value) from None
        return obj, end
The error states that the first character (char 0) does not match a valid JSON object (which likely means it is not something like {, [, or ( ). Unfortunately, the exception formatting does not /print/ "s" to show what it found (it is passed to the exception only for use in computing the line/column values).
Thats why I suggested he just reimage and start over with a fresh image that will work out of the box. I've already spent more time typing this one post up than the time it would take for him to reimage. Its just the easier route to get back to a fully working hotspot.
While the shell script is finding /something/ for the API Key, I think I'd go on Brandmeister, invalidate the existing key, and generate a new key to be cut&pasted into Pi-Star's BM configuration page. Possible a key is there, but it is corrupted.

--
AF6VN
Dennis L Bieber

Post Reply