I'm writing a bash script on a Windows machine that enters a PetaLinux machine over a serial connection, performs some commands, and should exit back to the bash script to continue performing commands. I'm unable to exit back to the bash script so far.
Here is what I have tried:
#!/bin/bash
echo "Running board bring up script"
BOARD_A_SERIAL_PORT="COM22"
plink -serial "$BOARD_A_SERIAL_PORT" -sercfg 115200,8,n,1,X -batch <<EOF
root
root
sleep 2
ps aux | grep plink
ps aux | grep plink
killall -9 plink
ps aux | grep [p]link
exit
EOF
echo 'script successfully exited' #never reached. the serial terminal hangs
You are running the
killall
on the remote server. But you need to run it locally.Here is an example how to achieve this in Windows batch file:
Send commands via COM port using plink and exit
It shows how to run the
taskkill
locally, while theplink
in running. The key point is not to provide a static input via heredoc [<<EOF
], but use a subshell [the( )
]. The subshell allows you to both produce the input usingecho
commands, but also to run thesleep
andkillall
locally.Translating that Widows batch file to Linux/bash tools and adjusting to your needs, you can do something like:
Not tested. Plus, I'm not a bash expert, and I'm sure there's more elegant way to achieve this in bash.