lh.sh
· 1.5 KiB · Bash
Raw
#!/usr/bin/env bash
# Get last heard time via ham-digital.org
# Author: Dominic Reich, OE7DRT <quick.hat4396@qtztsjosmprqmgtunjyf.com>
#
# Good DX and vy 73 de OE7DRT
command -v w3m > /dev/null 2>&1 || { echo >&2 "w3m not found"; exit 1; }
print_usage () {
echo >&2 "usage: `basename $0` [dmr_id | callsign]"
exit 1
}
if [ $# -ne 1 ]
then
print_usage
fi
getLH () {
CALL=`echo $1 | tr a-z A-Z`
FILE=/tmp/$CALL
OUTFILE=/tmp/${CALL}_LH
w3m "https://ham-digital.org/dmr-lh.php?callsign=$CALL" > $FILE
c=`grep $CALL $FILE | wc -l | xargs`
while [ $c -gt 0 ]
do
#OUT=`grep $CALL $FILE | head -n $c | tail -n 1 | awk '{ print $2,$3,$5,$6,$4,$8,$9,$13,$10 }'`
#OUT=`grep $CALL $FILE | head -n $c | tail -n 1 | awk '{ print $6,"was last heard on",$2,$3,"via",$9 }'`
OUT=`grep $CALL $FILE | head -n $c | tail -n 1`
echo $OUT >> $OUTFILE
((c--))
done
if [ ! -s $OUTFILE ]
then
echo No records found for »${CALL}«
rm ${FILE}
exit 1
fi
sort $OUTFILE
rm $FILE $OUTFILE
}
getCALLSIGN () {
ID=$1
FILE=/tmp/$ID
w3m "https://ham-digital.org/dmr-userreg.php?usrid=$ID" > $FILE
CALL=`grep $ID $FILE | awk '{ print $4 }'`
rm $FILE
if [ -z $CALL ]
then
exit 1
fi
getLH $CALL
}
checkID () {
if [[ ! $1 =~ ^[0-9]{7}$ ]]
then
echo >&2 "no valid dmr_id supplied"
exit 1
fi
}
if [ "$1" -eq "$1" ] 2>/dev/null
then
ID="$1"
checkID $ID
else
CALL="$1"
fi
if [ ! -z $ID ]
then
getCALLSIGN $ID
exit 0
elif [ ! -z $CALL ]
then
getLH $CALL
exit 0
else
print_usage
fi
1 | #!/usr/bin/env bash |
2 | # Get last heard time via ham-digital.org |
3 | # Author: Dominic Reich, OE7DRT <quick.hat4396@qtztsjosmprqmgtunjyf.com> |
4 | # |
5 | # Good DX and vy 73 de OE7DRT |
6 | |
7 | command -v w3m > /dev/null 2>&1 || { echo >&2 "w3m not found"; exit 1; } |
8 | |
9 | print_usage () { |
10 | echo >&2 "usage: `basename $0` [dmr_id | callsign]" |
11 | exit 1 |
12 | } |
13 | |
14 | if [ $# -ne 1 ] |
15 | then |
16 | print_usage |
17 | fi |
18 | |
19 | getLH () { |
20 | CALL=`echo $1 | tr a-z A-Z` |
21 | FILE=/tmp/$CALL |
22 | OUTFILE=/tmp/${CALL}_LH |
23 | w3m "https://ham-digital.org/dmr-lh.php?callsign=$CALL" > $FILE |
24 | c=`grep $CALL $FILE | wc -l | xargs` |
25 | |
26 | while [ $c -gt 0 ] |
27 | do |
28 | #OUT=`grep $CALL $FILE | head -n $c | tail -n 1 | awk '{ print $2,$3,$5,$6,$4,$8,$9,$13,$10 }'` |
29 | #OUT=`grep $CALL $FILE | head -n $c | tail -n 1 | awk '{ print $6,"was last heard on",$2,$3,"via",$9 }'` |
30 | OUT=`grep $CALL $FILE | head -n $c | tail -n 1` |
31 | echo $OUT >> $OUTFILE |
32 | ((c--)) |
33 | done |
34 | if [ ! -s $OUTFILE ] |
35 | then |
36 | echo No records found for »${CALL}« |
37 | rm ${FILE} |
38 | exit 1 |
39 | fi |
40 | sort $OUTFILE |
41 | rm $FILE $OUTFILE |
42 | } |
43 | |
44 | getCALLSIGN () { |
45 | ID=$1 |
46 | FILE=/tmp/$ID |
47 | w3m "https://ham-digital.org/dmr-userreg.php?usrid=$ID" > $FILE |
48 | CALL=`grep $ID $FILE | awk '{ print $4 }'` |
49 | rm $FILE |
50 | if [ -z $CALL ] |
51 | then |
52 | exit 1 |
53 | fi |
54 | getLH $CALL |
55 | } |
56 | |
57 | checkID () { |
58 | if [[ ! $1 =~ ^[0-9]{7}$ ]] |
59 | then |
60 | echo >&2 "no valid dmr_id supplied" |
61 | exit 1 |
62 | fi |
63 | } |
64 | |
65 | if [ "$1" -eq "$1" ] 2>/dev/null |
66 | then |
67 | ID="$1" |
68 | checkID $ID |
69 | else |
70 | CALL="$1" |
71 | fi |
72 | |
73 | if [ ! -z $ID ] |
74 | then |
75 | getCALLSIGN $ID |
76 | exit 0 |
77 | elif [ ! -z $CALL ] |
78 | then |
79 | getLH $CALL |
80 | exit 0 |
81 | else |
82 | print_usage |
83 | fi |
84 |