-
Notifications
You must be signed in to change notification settings - Fork 0
/
updatedbs.sh
executable file
·50 lines (48 loc) · 1.07 KB
/
updatedbs.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
#!/bin/bash
trap ' ' 2 20
spinerFunction(){
local i sp n
chars="/-\|"
n=${#chars}
printf ' '
while sleep 0.1; do
printf "%s\b" "${chars:i++%n:1}"
done
}
sudo openvpn "$1" &> /dev/null &
firstLine="$(head -1 $2)"
if [ ! -d .temcsv/ ];then
mkdir .temcsv
cd .temcsv/
touch .tem
else
cd .temcsv/
touch .tem
fi
tail -n +2 "$2">.tem
sed -i 's/\"//g' .tem
IFC=""
while read i; do
tt="$(cut -d "," -f 1 <<<"$i")"
ipsrc="$(cut -d "," -f 2 <<<"$i")"
ipdst="$(cut -d "," -f 3 <<<"$i")"
protocol="$(cut -d "," -f 4 <<<"$i")"
length="$(cut -d "," -f 5 <<<"$i")"
info="$(cut -d "," -f 6 <<<"$i")"
printf "\n"
printf "Saving remote data "
spinerFunction &
sleep 3
kill "$!"
ssh "$3@$4" << EOF
mariadb -u root -proot ids -e "INSERT INTO traffic (time, ipsrc, ipdst, protocol, packlen, info) VALUES ($tt, '$ipsrc', '$ipdst', '$protocol', $length, '$info')"
EOF
done<.tem
echo "Saved Data returning to main menu..."
rm -rf .temcsv
cd ../..
echo "Exit from VPN..."
pkill openvpn
sleep 3
clear
trap - 2 20