Page 1 of 1

Link to D-Star reflectors from the command line

Posted: Wed Oct 10, 2018 10:30 pm
by N7HHI
Command Line Reflector Linking

I have written a BASH Shell Script for linking to reflectors via the command line. Below is a screen capture showing the output of the script:
Screen Capture for Command Line Linking
Screen Capture for Command Line Linking
CommandLineLinking.png (32.23 KiB) Viewed 13378 times

The script is shown in the code block below:

Code: Select all

#!/bin/bash
####################################
#
# Script to link to Dstar reflector
#
# Scott Showalter - N7HHI - 10/06/2018
#
####################################

# ${0} is the script name
# $(basename ${0}) strips the first portion of the PATH so that only the script name is returned
# ${1} is the number of the reflector
# ${2} is the port of the reflector
#

if [ $# -ne 2 ]; then
  echo "Usage: $(basename ${0}) [number] [port]"
  echo ""
  echo "[number] = reflector number"
  echo "[port] = Alphabetic port representation [a-z] (not case sensitive)"
  echo "e.g. ref 001 c  - in order to link to ref001 C"
  echo "e.g. dcs 757 a  - in order to link to dcs757 A"
  echo "e.g. xrf 307 d  - in order to link to xrf307 D"
  echo ""
  exit 1
fi

# Set RDX to lowercase Reflector type
RDX="$(echo $(basename ${0}) | tr '[A-Z]' '[a-z]')"

# Set REPN to Repeter Number padded to 3 characters
# If user enters less than 3 digits, pad with leading zeros to total 3 characters
REPN=$(printf "%03d" ${1})

# Set PORT to lowercase Port, in order to make the entry case-insensitive
PORT="$(echo ${2} | tr '[A-Z]' '[a-z]')"

# Link to Reflector and redirect stdout and stderr to /dev/null
sudo pistar-link ${RDX}${REPN}_${PORT} >/dev/null 2>&1

#   Wait 1 second. This is needed for the linked repeater to show up in the
#    /var/log/pi-star/Links.log file prior to displaying it.
sleep 1

#Display the linked to reflector as determined from /var/log/pi-star/Links.log
echo "Linked to $(awk '{print $12, $13}' /var/log/pi-star/Links.log)"
I addition to the script, I have created links to the script for each way that I want to be able to call the script. If I want to link to a DPlus Reflector you use the link for REF or ref. If you want to link to a DPlus reflector you use the link for XRF or xrf. If you want to link to a DCS reflector you use the link for DCS or dcs.

I created this script as /home/pi-star/bin/ref.
  1. Go into Read/Write mode: rpi-rw
  2. Make the directory to store the script (in my case, I called it bin): mkdir /home/pi-star/bin
  3. Change to the bin directory: cd /home/pi-star/bin
  4. Copy the above script to the new directory and call it by one of the names for the type of reflector: nano ref
  5. Paste the contents into the nano editor. Save the file: CTRL O
  6. Press [Enter] to accept the default name you specified when opening the editor: [Enter]
  7. Exit the editor: CTRL X
  8. Give execute permissions to the script: chmod 755 /home/pi-star/bin/ref
You now have an executable script that you can call by typing /home/pi-star/bin/ref 001 c
If you want to be able to just type ref 001 c, then you need to add /home/pi-star/bin to your PATH environment variable. To do that edit the /home/pi-star/.bashrc file and add the following lines to it:

Code: Select all

PATH=${PATH}:/home/pi-star/bin
After logging out and logging back in you will have the bin directory in your path so that you will not have to include the path in your command.

Next create the additional links for the DPlus and DCS reflectors:

Code: Select all

ln ref xrf
ln ref dcs
Now you can issue commands like:

Code: Select all

xrf 307 d
dcs 757 a
If you want to make it so that you can use UPPER CASE letters for REF, XRF, and DCS, then add these additional links:

Code: Select all

ln ref REF
ln ref XRF
ln ref DCS
After doing this, your /home/pi-star/bin directory will look similar to the following:

Code: Select all

pi-star@pi-star(rw):bin$ ls -l
total 24
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 dcs
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 DCS
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 ref
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 REF
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 xrf
-rwxrw-rw- 6 pi-star pi-star 1406 Oct  6 13:10 XRF
Now to link to REF001 C, you can enter REF 1 C or ref 1 c
To link to XRF307 D, you can enter XRF 307 D or xrf 307 d
To link to DCS757 A, you can enter DCS 757 A or dcs757 a

Put pi-star back into Read Only mode: rpi-ro



**** Moderators Edit ****

Great that you are writing scripts and putting then up on the board, and not wanting to take away from the work you have done, but

Pistar has the ability to link from the command line written in, using Pistar-link.

**** Moderators Edit ****


Re: Link to D-Star reflectors from the command line

Posted: Fri Oct 12, 2018 5:32 am
by G6WQH
Thank you - I will try this later - I can see it being very useful!

Re: Link to D-Star reflectors from the command line

Posted: Wed Nov 14, 2018 6:57 am
by W4JEW
VERY NICE!!!

Re: Link to D-Star reflectors from the command line

Posted: Sat Jan 19, 2019 9:41 pm
by MW0MWZ
I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?

Re: Link to D-Star reflectors from the command line

Posted: Sat Jan 19, 2019 9:59 pm
by KE0FHS
MW0MWZ wrote: Sat Jan 19, 2019 9:41 pm I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?
Wow, that's the first time I've heard of pistar-link. Nice! Any other gems like that?

Re: Link to D-Star reflectors from the command line

Posted: Sat Jan 26, 2019 4:49 pm
by N7HHI
MW0MWZ wrote: Sat Jan 19, 2019 9:41 pm I'm pleased to see people writing their own scripts, but was "pistar-link" really too hard to use ?
Hi Andy,

Not that "pistar-link" was that hard to use, but my 62 year old brain couldn't remember the name and/or syntax without the need to look it up each time I went to use it. Just typing the reflector name and module was easier for me to remember. ;)

Re: Link to D-Star reflectors from the command line

Posted: Thu Mar 21, 2019 7:51 pm
by KM6YNK
where can I find the documentation on pistar-link command?

Re: Link to D-Star reflectors from the command line

Posted: Thu Mar 21, 2019 8:10 pm
by M1DNS
KM6YNK wrote:where can I find the documentation on pistar-link command?
viewtopic.php?t=326#p1091

Andrew M1DNS, (Mod)


Re: Link to D-Star reflectors from the command line

Posted: Wed Nov 17, 2021 10:17 pm
by SA0BUX
I discovered one problem with this script.

The line REPN=$(printf "%03d" ${1}) will return the octal value of ${1} if the value begins with 0 (zero)

So "xlx 010 b" will try to connect to xlx008b instead of xlx010b.

Numbers with a leading 0 is treated as octal in bash and this seems tricky to fix in scripts as all leading zeros needs to be removed.

https://www.unix.com/shell-programming- ... cimal.html

So remove leading zeros manually is probably easiest.

Re: Link to D-Star reflectors from the command line

Posted: Wed Jan 26, 2022 6:30 am
by VK2ZCD
Excellent script, Thank you

Ian VK2YG