dominic revidoval tento gist . Přejít na revizi
1 file changed, 83 insertions
lh.sh(vytvořil soubor)
@@ -0,0 +1,83 @@ | |||
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 |
Novější
Starší