-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_collect_data.sh
54 lines (45 loc) · 1.42 KB
/
deploy_collect_data.sh
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
#!/bin/bash
remotehost="http://file2.gbcbooks.eu.org:8092"
scriptpath="scripts"
workdir="/usr/local/scripts/auto-bgp-correct"
databasedir="${workdir}/db"
workscriptdir="${workdir}/$scripts"
create_dir(){
sudo mkdir ${workdir} -p
sudo mkdir ${databasedir} -p
sudo mkdir ${databasedir} -p
}
download_file(){
# curl -4 -s ${remotehost}/${scriptpath}/collect_data.sh -o ${workdir}/collect_data.sh
# curl -4 -s ${remotehost}/${scriptpath}/target -o ${workdir}/target
# curl -4 -s ${remotehost}/${scriptpath}/get_avg_5m_loss.sh -o ${workdir}/get_avg_5m_loss.sh
# curl -4 -s ${remotehost}/${scriptpath}/get_avg_5m_delay.sh -o ${workdir}/get_avg_5m_delay.sh
cd /usr/local/scripts/
git clone https://github.com/gbcbooks/auto-bgp-correct.git
}
add_crontjob(){
crontab -l | sed "/collect ping date/d;/collect_data.sh/d" > /tmp/cront.tmp
echo "## collect ping date" >> /tmp/cront.tmp
echo "*/1 * * * * /bin/bash /usr/local/scripts/auto-bgp-correct/collect_data.sh > /dev/null 2>&1" >> /tmp/cront.tmp
crontab /tmp/cront.tmp
}
check_user(){
# 需要root用户执行本脚本
user=$(env | grep "^USER=" | sed "s/=/ /" | awk '{print $2}')
if [ $user != "root" ];then
return 1
else
return 0
fi
}
main(){
check_user
if [ $? -eq 1 ];then
echo "please run script as root !!!"
exit 1
fi
create_dir
download_file
add_crontjob
}
main $*