forked from mickaelreil/project-session-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.sh
More file actions
executable file
·45 lines (37 loc) · 1.17 KB
/
agent.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.17 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
#!/bin/bash
#PASSWD
id=$1
log_f="log.tmp"
center="mickael@172.16.131.74"
if [ "$PASS" = "" ]
then
echo -n "password : "
read -s input
echo ""
PASS=$input
sed -e 's/^#PASSWD/PASS="'$PASS'"/g' agent.sh > agent.tmp.sh
fi
host=$USER"@"$(ip a | grep "inet " | tail -1 | cut -d " " -f 6 | cut -d "/" -f 1)
remote=$(sed -n "1p" config)
if [ "$remote" != "" ]
then
echo "From : "$host
echo "To : "$remote
sed -i "1d" config
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $remote 2> /dev/null
ssh $remote "
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $host 2> /dev/null;
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $center 2> /dev/null;
scp -o StrictHostKeyChecking=no $host:config $remote:config;
scp -o StrictHostKeyChecking=no $host:agent.tmp.sh $remote:agent.tmp.sh;
scp -o StrictHostKeyChecking=no $host:analyze.tmp.sh $remote:analyze.tmp.sh;
chmod u+x agent.tmp.sh;
chmod u+x analyze.tmp.sh;
./analyze.tmp.sh $log_f;
scp -o StrictHostKeyChecking=no $log_f $center:log/log-$remote;
rm $log_f;
./agent.tmp.sh $id;"
fi
rm agent.tmp.sh 2> /dev/null
rm config 2> /dev/null
rm analyze.tmp.sh 2> /dev/null