-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasnames.sh
More file actions
executable file
·82 lines (69 loc) · 1.56 KB
/
Copy pathasnames.sh
File metadata and controls
executable file
·82 lines (69 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# $Id: $
# script that gets and updates AS numbers and names from RIPE
# enable for debugging
#set -x
# set group permissions
umask 022
WORKDIR=${HOME}/opt/asnames
DSTDIR=${HOME}/etc
DST_ASNAMES=${DSTDIR}/asnames.txt
SRC_ASNAMES=https://ftp.ripe.net/ripe/asnames/asn.txt
PID=$$
PIDFILE=${WORKDIR}/asnames.pid
DISABLED=${WORKDIR}/asnames.DISABLED
PURGE_TIME=7
CURL=/usr/bin/curl
warning() {
echo ${1:-${DEFAULT_WARNING}} >&2
}
error() {
echo ${1:-${DEFAULT_ERROR}} >&2
exit 1
}
# quit if we are already running
if test -r ${PIDFILE}
then
if [ "$(ps -p `cat ${PIDFILE}` | wc -l)" -gt 1 ]
then
error "script already running"
else
# orphaned pid file
rm ${PIDFILE}
fi
fi
# quit if we are disabled
if test -r ${DISABLED}
then
error "script disabled, remove file to enable: ${DISABLED}"
fi
# make sure work directories exist
if test ! -d ${WORKDIR}
then
mkdir -p ${WORKDIR} || error "mkdir: ${WORKDIR}"
fi
if test ! -d ${DSTDIR}
then
mkdir -p ${DSTDIR} || error "mkdir: ${DSTDIR}"
fi
echo $$ > ${PIDFILE}
if test ! -r ${PIDFILE}
then
error "pidfile creation error: ${PIDFILE}"
fi
# ASNAMES
TMPFILE=${WORKDIR}/`basename ${DST_ASNAMES}`.${PID}
SRCFILE=${SRC_ASNAMES}
DSTFILE=${DST_ASNAMES}
${CURL} -k -s -S -o ${TMPFILE} ${SRCFILE}
if [ "$?" -ne 0 ]
then
error "curl ${SRCFILE} failed"
fi
cp ${TMPFILE} ${DSTFILE} || error "cp ${TMPFILE} failed"
rm ${TMPFILE}
# remove old work files if any exist
find ${WORKDIR} -type f -mtime +${PURGE_TIME} -print | xargs rm -f
# clean up and exit
rm ${PIDFILE}
exit 0