-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc-v3-only
172 lines (146 loc) · 3.23 KB
/
.bashrc-v3-only
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# -*- sh -*-
function delete_key()
{
local host
local ip
if [[ $1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] ; then
ip=$1
host=$(host ${ip} | cut -d' ' -f5)
echo "IP = $1 HOST=${host}"
else
host=$1
ip=$(host ${host} | cut -d' ' -f4)
echo "HOST=$1 IP=${ip}"
fi
ssh-keygen -R ${host}
ssh-keygen -R ${ip}
}
function rs()
{
local ARG=$1
local host
local user=${USER}
if [[ ${ARG} =~ "@" ]] ; then
user=$( echo ${ARG} | cut -d'@' -f1 )
host=$( echo ${ARG} | cut -d'@' -f2 )
else
host=${ARG}
fi
if [[ -n "$2" && "$2" = "-l" ]] ; then
if [ -n "$3" ] ; then
user=$3
fi
fi
echo "Shelling for ${user} @ ${host}"
if [ "${user}" = "${USER}" ] ; then
xtitle "${host}"
else
xtitle "${user}@${host}"
fi
ssh ${user}@${host}
export TITLE=
}
function rsession()
{
local ARG=$1
local host
local user=${USER}
if [[ ${ARG} =~ "@" ]] ; then
user=$( echo ${ARG} | cut -d'@' -f1 )
host=$( echo ${ARG} | cut -d'@' -f2 )
else
host=${ARG}
fi
if [ -n "$2" ] ; then
echo "Resuming session $2"
fi
echo "Shelling for ${user} @ ${host}"
if [ "${user}" = "${USER}" ] ; then
xtitle "${host}"
else
xtitle "${user}@${host}"
fi
#ssh -tt ${user}@${host} "tmux attach-session -t $2"
ssh -tt ${ARG} "( (tmux has-session -t $2 && tmux attach-session -t $2) || (tmux new-session -s $2) ) && exit 0"
}
function lsession()
{
local name=$1
( (tmux has-session -t ${name} && tmux attach-session -t ${name}) || (tmux new-session -s ${name}) )
}
function wait_for_port()
{
local HOST=$1
local PORT=$2
local keep_going
local output
local banner
keep_going=0
while [ $keep_going -eq 0 ] ; do
output=$(nc -d -w 2 ${HOST} ${PORT})
if [ $? -eq 0 ] ; then
if [ "${PORT}" = "22" ] ; then
if [[ ${output} =~ OpenSSH ]] ; then
keep_going=1
return 0
fi
else
keep_going=1
return 0
fi
fi
sleep 5
done
}
function copy_pxe_config()
{
local HOST=$1
local FILE=$2
local mac=$(pxe_mac $HOST)
if [[ "${mac}" =~ /unable/ ]] ; then
echo "Unable to find mac address for ${HOST}"
else
rm -vf /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
cp -vf ${FILE} /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
chmod -v 777 /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
fi
}
function wait_host()
{
local keep_going
local output
local banner
local chars=( "-" "\\" "|" "/" )
local count=0
local keep_going=0
declare -i TIMER
TIMER=0
SLEEP_TIME=5
TIMEOUT=$(( 60/${SLEEP_TIME}*240 ))
echo -n "Waiting for port $2 on $1: "
while [ $keep_going -eq 0 ] ; do
output=$(nc -d -w 2 $1 $2)
if [ $? -eq 0 ] ; then
if [ "$2" = "22" ] ; then
if [[ ${output} =~ OpenSSH ]] ; then
keep_going=1
return 0
fi
else
keep_going=1
return 0
fi
fi
pos=$(($count % 4))
echo -en "\b${chars[$pos]}"
count=$(($count + 1))
sleep ${SLEEP_TIME}
TIMER=$(( ${TIMER}+${SLEEP_TIME} ))
if [ ${TIMER} -gt ${TIMEOUT} ] ; then
echo "Timeout waiting for port $2 on $1..."
keep_going=1
exit 1
fi
done
echo -e "\b **** Host $1 ready"
}