Merge pull request #84 from phl0/cron

Add cron scripts for automatic update of DMRIDs.dat
This commit is contained in:
Kim - DG9VH 2017-01-18 13:25:34 +01:00 committed by GitHub
commit 00c349b3f6
3 changed files with 37 additions and 0 deletions

View file

@ -52,6 +52,10 @@ New features by EA4GKQ
* LastHeard table are sorted * LastHeard table are sorted
* Some mods to improve mobile experience * 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 Contact
======= =======
Feel free to contact the author via email: dg9vh[@]darc.de Feel free to contact the author via email: dg9vh[@]darc.de

4
cron/updateDMRIDs Normal file
View file

@ -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

29
cron/updateDMRIDs.sh Executable file
View file

@ -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)