-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_ex_vm
executable file
·52 lines (48 loc) · 1.33 KB
/
run_ex_vm
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
#!/usr/bin/env dash
# set -e
# select vm
#
vm_name=eyantra
host_name=vm20
user_name=tusqasi
# check if running
# if running then skip starting
# else start vm
# check if network is up
# if up
# start tmux
# check till network is up
# check if ssh is up
vm_started=$(sudo virsh list --state-running |grep $vm_name)
# check vm started
echo $vm_started dsf
while [ -z "${vm_started}" ];do
echo "vm not started\n starting again"
sudo virsh start $vm_name
vm_started=$(sudo virsh list --state-running |grep $vm_name)
done
echo vm running
ip=$(sudo virsh net-dhcp-leases default |grep "$vm_name"|awk '{print $(NF-2)}'|cut -d'/' -f1)
echo ip: $ip
while [ -z "${ip}" ];do
echo no ip. wait
sleep 4
echo ip: $ip
sudo virsh net-dhcp-leases default
ip=$(sudo virsh net-dhcp-leases default |grep "$host_name"|awk '{print $(NF-2)}'|cut -d'/' -f1)
done
session_name=eyantra
tmux new-session -A -d -s "$session_name"
tmux switch-client -t $session_name:
tmux splitw -t $session_name:
sleep 3
tmux send-keys -t $session_name:1.1 "ssh $user_name@$ip" Enter
sleep 0.5
# tmux send-keys -t $session_name:1.1 "zsh" Enter
sleep 0.5
# tmux send-keys -t $session_name:1.1 "cd " Enter
sleep 0.5
tmux send-keys -t $session_name:1.0 "sshfs $user_name@$ip:/home/$user_name/ ~/eyantra_vm" Enter
sleep 0.5
tmux send-keys -t $session_name:2.0 "cd ~/eyantra_vm" Enter
echo done