Link to D-Star reflectors from the command line

Post your tips and tricks here
Post Reply
User avatar
N7HHI
Posts: 18
Joined: Thu Apr 12, 2018 11:33 pm
Location: Wentzville, MO
Contact:

Link to D-Star reflectors from the command line

Post by N7HHI » Wed Oct 10, 2018 10:30 pm

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:
CommandLineLinking.png
Screen Capture for Command Line Linking
CommandLineLinking.png (32.3 KiB) Viewed 399 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

[email protected](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
73...
Scott - N7HHI

User avatar
G6WQH
Posts: 6
Joined: Mon Jun 18, 2018 6:27 pm

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

Post by G6WQH » Fri Oct 12, 2018 5:32 am

Thank you - I will try this later - I can see it being very useful!

W4JEW
Posts: 18
Joined: Sun Aug 12, 2018 12:53 am

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

Post by W4JEW » Wed Nov 14, 2018 6:57 am

VERY NICE!!!

Post Reply