-
Notifications
You must be signed in to change notification settings - Fork 9
/
ssh.sh
executable file
·50 lines (38 loc) · 1.12 KB
/
ssh.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
#!/bin/sh
# If you fully UNDERSTAND what you are doing, it won't be annoying anymore
#
# $HOME/.ssh/config
# Host 10.*.*.*
# StrictHostKeyChecking no
# UserKnownHostsFile /dev/null
if [ $# -lt 1 ]; then
echo "Usage: $0 <device ip> <args>"
exit
fi
# load credentials if exists
[ -r ~/.creds ] && . ~/.creds
DEVICE_IP="$1"
[ -n "$2" ] && ARGS="$2"
echo "Waiting for device to go online"
until nc -vzw 2 $DEVICE_IP 22 2>/dev/null; do sleep 0.3; done
# Put .bashrc for busybox file on remote server
BASHRC_BB=".bashrc_bb_u"
SSH_OPTION_IGNORE_CHECK="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
for passwd in ${SSH_PASS:-ubnt}; do
sshpass -p ${passwd} scp -O $SSH_OPTION_IGNORE_CHECK `dirname $0`/$BASHRC_BB ${SSH_USER:-ubnt}@$DEVICE_IP:/tmp/
[ $? -eq 0 ] && break || echo "try next..."
done
expect -c "
set timeout 3
spawn sshpass -p $passwd ssh $SSH_OPTION_IGNORE_CHECK ${SSH_USER:-ubnt}@$DEVICE_IP
send \"FROM_ID='`whoami`'\r\"
send \"source /tmp/$BASHRC_BB\r\"
send \"date\r\"
send \"$ARGS\r\"
interact timeout 60 { }
"
# FIXME: It's weird/buggy to rewrite as below well-known form
# expect << EOF
# ...
# ...
# EOF