Add cron stuff for updating DMRIDs

This commit is contained in:
phl0 2017-01-18 12:00:09 +01:00
parent 4999b0124e
commit bae5bf2fe7
No known key found for this signature in database
GPG key ID: 48EA1E640798CA9A
3 changed files with 37 additions and 0 deletions

View file

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

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)