From bae5bf2fe7517df4f8a3736ab4c1c4c8783fc404 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 18 Jan 2017 12:00:09 +0100 Subject: [PATCH 1/2] Add cron stuff for updating DMRIDs --- README.md | 4 ++++ cron/updateDMRIDs | 4 ++++ cron/updateDMRIDs.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 cron/updateDMRIDs create mode 100755 cron/updateDMRIDs.sh diff --git a/README.md b/README.md index 436472c..8cac383 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ New features by EA4GKQ * LastHeard table are sorted * Some mods to improve mobile experience +Cronjob for updating DMR IDs +============================ +You can use the included script to update the DMR IDs periodically. Copy the file updateDMRIDs to /etc/cron.d/ and updateDMRIDs.sh to /var/www. The paths may have to be aligned to your system architecture. The Update script will then be executed once every 24 hours at 3:30. For security considerations please make sure that the cron folder is not copied to your web server's www root directory. + Contact ======= Feel free to contact the author via email: dg9vh[@]darc.de diff --git a/cron/updateDMRIDs b/cron/updateDMRIDs new file mode 100644 index 0000000..aeda16a --- /dev/null +++ b/cron/updateDMRIDs @@ -0,0 +1,4 @@ +# Move this file to /etc/cron.d +# Updates the DMRIds.dat every 24 hours +* * * * * www-data [ -x /var/www/updateDMRIDs.sh ] && /var/www/updateDMRIDs.sh + diff --git a/cron/updateDMRIDs.sh b/cron/updateDMRIDs.sh new file mode 100755 index 0000000..067126c --- /dev/null +++ b/cron/updateDMRIDs.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# Full path to DMR ID file +DMRIDFILE=/var/www/html/DMRIds.dat + +# How many DMR ID files do you want backed up (0 = do not keep backups) +DMRFILEBACKUP=1 + +# Create backup of old file +if [ ${DMRFILEBACKUP} -ne 0 ] +then + cp ${DMRIDFILE} ${DMRIDFILE}.$(date +%d%m%y) +fi + +# Prune backups +BACKUPCOUNT=$(ls ${DMRIDFILE}.* | wc -l) +BACKUPSTODELETE=$(expr ${BACKUPCOUNT} - ${DMRFILEBACKUP}) + +if [ ${BACKUPCOUNT} -gt ${DMRFILEBACKUP} ] +then + for f in $(ls -tr ${DMRIDFILE}.* | head -${BACKUPSTODELETE}) + do + rm $f + done +fi + +curl 'http://www.dmr-marc.net/cgi-bin/trbo-database/datadump.cgi?table=users&format=csv&header=0' 2>/dev/null | sed -e 's/\t//g' | awk -F"," '/,/{gsub(/ /, "", $2); printf "%s\t%s\t%s\n", $1, $2, $3}' | sed -e 's/\(.\) .*/\1/g' > /tmp/DMRIds.dat.$(date +%d%m%y) +mv /tmp/DMRIds.dat.$(date +%d%m%y) ${DMRIDFILE} +rm -f /tmp/DMRIds.dat.$(date +%d%m%y) From 3bfab28535aa16953779ff5acf5f126bd617c0f9 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 18 Jan 2017 12:02:20 +0100 Subject: [PATCH 2/2] Update README according to cron jobs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8cac383..75d98b4 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ New features by EA4GKQ Cronjob for updating DMR IDs ============================ -You can use the included script to update the DMR IDs periodically. Copy the file updateDMRIDs to /etc/cron.d/ and updateDMRIDs.sh to /var/www. The paths may have to be aligned to your system architecture. The Update script will then be executed once every 24 hours at 3:30. For security considerations please make sure that the cron folder is not copied to your web server's www root directory. +You can use the included script to update the DMR IDs periodically. Copy the files updateDMRIDs to /etc/cron.d/ and updateDMRIDs.sh to /var/www from the cron folder in this repo. The paths may have to be aligned to your system architecture. The Update script will then be executed once every 24 hours at 3:30. For security considerations please make sure that the cron folder is not copied to your web server's www root directory. Contact =======