-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_scripts_fixed.py
More file actions
66 lines (61 loc) · 1.86 KB
/
write_scripts_fixed.py
File metadata and controls
66 lines (61 loc) · 1.86 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import subprocess
def run_ssh_command(ip, user, password, command):
print(f"\n=== CMD: {command} ===")
expect_script = f"""
set timeout 20
spawn ssh -o StrictHostKeyChecking=no {user}@{ip}
expect {{
"password:" {{
send "{password}\\r"
expect "$ " {{
send "{command}\\r"
expect "$ " {{
send "exit\\r"
expect eof
}}
}}
}}
"yes/no" {{
send "yes\\r"
exp_continue
}}
}}
"""
result = subprocess.run(['expect', '-c', expect_script], capture_output=True, text=True)
print(result.stdout)
target_ip = "172.18.161.85"
user = "classnova"
password = "hari1388"
# Using cat heredoc for start_nova.sh
cmd1 = """cat << 'EOF' > /home/classnova/start_nova.sh
#!/bin/bash
export DISPLAY=:0
export NODE_ENV=production
export NODE_OPTIONS="--max-old-space-size=1536"
cd /home/classnova/NovaBoard_Deployed/excalidraw-app
./node_modules/.bin/electron . --no-sandbox
EOF
chmod +x /home/classnova/start_nova.sh
"""
# Using cat heredoc for kiosk.sh
cmd2 = """cat << 'EOF' > /home/classnova/kiosk.sh
#!/bin/bash
export DISPLAY=:0
pkill -f lxpanel
pkill -f pcmanfm
unclutter -idle 0 &
VIDEO_PATH="$HOME/Downloads/video1.mp4"
if [ -f "$VIDEO_PATH" ]; then
cvlc --fullscreen --no-video-title-show --play-and-exit "$VIDEO_PATH"
fi
while true; do
/home/classnova/start_nova.sh >> /home/classnova/nova_run.log 2>&1
sleep 2
done
EOF
chmod +x /home/classnova/kiosk.sh
"""
run_ssh_command(target_ip, user, password, cmd1)
run_ssh_command(target_ip, user, password, cmd2)
run_ssh_command(target_ip, user, password, "pkill -f npm; pkill -f node; pkill -f electron; pkill -f kiosk.sh")
run_ssh_command(target_ip, user, password, "nohup /home/classnova/kiosk.sh > /home/classnova/kiosk_startup.log 2>&1 &")