I'm trying to execute a script in screen
through expect
with ssh
, but it's never executed. I know this because I do not see a screen
session with screen -list
. Expect
s' exit code is 0. If I execute the command through SSH manually, it works.
What am I doing wrong? (Other ways to achieve my goal are welcome as well).
The script:
#! /bin/bash
expect -d <<-EOF
set timeout -1
spawn ssh ${user}@${host}
expect {
"yes/no" { send "yes\r"; exp_continue }
"password: " { send "${pass}\r" }
}
expect "*# "
send "screen -dm bash -c './${CLIENT_SCRIPT_LOG}'\r"
exit 0
EOF
exit $?
Debug output:
[.. cut ..]
expect: set expect_out(buffer) "\r\nLinux client 4.9.76-Rxx-rt61-gb7ccafd-dirty #1 SMP PREEMPT RT Wed Apr 1 13:14:00 CEST 2020 armv7l\r\n\r\nThe programs included with the Debian GLinux system are free software;\r\nthe exact distribution terms for each program are described in the\r\nindividual files in /usr/share/doc/*/copyright.\r\n\r\nDebian GNU/Linux cs with ABSOLUTELY NO WARRANTY, to the extent\r\npermitted by applicable law.\r\nLast login: Thu Jan 1 05:29:03 1970 from 192.168.138.2\r\r\nroot@client:~# "
send: sending "screen -dm bash -c './log.sh'\r" to { exp5 }
Versions client:
- Debian Wheezy
- Bash 4.2.37
- Screen 4.01.00devel
Versions host:
- Debian Stretch
- Bash 4.4.12(1)-release
- Screen version 4.05.0
- Expect 5.45