diff --git a/README.md b/README.md index 436472c..75d98b4 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 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 ======= 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)