From 321f274c32824d3b6fb970ae1ee64e4e17751b3d Mon Sep 17 00:00:00 2001 From: Michael Clemens Date: Mon, 9 Nov 2020 17:22:11 +0100 Subject: [PATCH] initial commit --- .qrz.conf | 4 +++ README.md | 7 +++++ qrz.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 .qrz.conf create mode 100755 qrz.sh diff --git a/.qrz.conf b/.qrz.conf new file mode 100644 index 0000000..79d58e7 --- /dev/null +++ b/.qrz.conf @@ -0,0 +1,4 @@ +# enter here your QRZ.com user name and password (NOT the API key) +# save this file to ~/qrz.conf +user=myusername +password=mypassword diff --git a/README.md b/README.md index 93458d0..df87065 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # qrz.sh QRZ.com callsign data query script written in Bash + +This script queries the QRZ.com callsign database and returns +the result to the command line. A XML subscription plan with +QRZ.com is required for full functionality. + +usage: ./qrz.sh + diff --git a/qrz.sh b/qrz.sh new file mode 100755 index 0000000..b97eb4f --- /dev/null +++ b/qrz.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# This script queries the QRZ.com callsign database and returns +# the result to the command line. A XML subscription plan with +# QRZ.com is required for full functionality. +# +# Copyright (C) 2020 Michael Clemens, DL6MHC +# +# usage: ./qrz.sh + + +# get username and password from config file +. ~/.qrz.conf + +# check if parameter has been supplied by user +if [ $# -ne 1 ] + then + echo "Error: You did not provide a callsign as parameter." + echo "Usage: ./qrz.sh " + echo "Example: ./qrz.sh dl6mhc" + exit +fi + +# check if username/password is configured in config file +if [ -z ${user+x} ] || [ -z ${password+x} ] + then + echo "Error: Username and/or password have not been configured correctly." + echo " Please create the file ~/.qrz.conf with the following content:" + echo " ------------------------" + echo " user:" + echo " password:" + echo " ------------------------" + exit + fi + +# get callsign +call=$1 + +# get a session key from qrz.com +session_xml=$(curl -s -X GET 'http://xmldata.qrz.com/xml/current/?username='${user}';password='${password}';agent=qrz_sh') + +# check for login errors +e=$(printf %s "$session_xml" | grep -oP "(?<=).*?(?=)" ) +if [ "$e" != "" ] + then + echo "The following error has occured: $e" + exit + fi + +# extract session key from response +session_key=$(printf %s "$session_xml" |grep -oP '(?<=).*?(?=)') + +# lookup callsign at qrz.com +lookup_result=$(curl -s -X GET 'http://xmldata.qrz.com/xml/current/?s='${session_key}';callsign='${call}'') + +# grep field values from xml and put them into variables +for f in "call" "fname" "name" "addr1" "addr2" "country" "grid" "email" "user" "lotw" "mqsl" "eqsl" "qslmgr" +do + z=$(printf %s "$lookup_result" | grep -oP "(?<=<${f}>).*?(?=)" ) + eval "$f='${z}'"; +done + +# return extracted information to user +echo "================================================================" +echo "QRZ.com results for $call:" +echo "================================================================" +echo "Call: $call" +echo "Name: $fname $name" +echo "Street: $addr1" +echo "City: $addr2" +echo "Country: $country" +echo "Grid: $grid" +echo "EMail: $email" +if [ "$call" != "$user" ] + then + echo "Manager: $user" + fi +echo "" +echo "================================================================" +echo "QSL Information" +echo "================================================================" +echo "QSL Info: $qslmgr" +if [ "$eqsl" == "1" ] + then + echo "eQSL: yes" + fi +if [ "$lotw" == "1" ] + then + echo "LoTW: yes" + fi +if [ "$mqsl" == "1" ] + then + echo "Paper QSL: yes" + fi