Last active 1731167903

lh.sh Raw
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
7command -v w3m > /dev/null 2>&1 || { echo >&2 "w3m not found"; exit 1; }
8
9print_usage () {
10 echo >&2 "usage: `basename $0` [dmr_id | callsign]"
11 exit 1
12}
13
14if [ $# -ne 1 ]
15then
16 print_usage
17fi
18
19getLH () {
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
44getCALLSIGN () {
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
57checkID () {
58 if [[ ! $1 =~ ^[0-9]{7}$ ]]
59 then
60 echo >&2 "no valid dmr_id supplied"
61 exit 1
62 fi
63}
64
65if [ "$1" -eq "$1" ] 2>/dev/null
66then
67 ID="$1"
68 checkID $ID
69else
70 CALL="$1"
71fi
72
73if [ ! -z $ID ]
74then
75 getCALLSIGN $ID
76 exit 0
77elif [ ! -z $CALL ]
78then
79 getLH $CALL
80 exit 0
81else
82 print_usage
83fi
84