As said in the title, I am writing a script that should run on Computer A. Computer A should ssh
on Computer B, run Program B, then exit the ssh
session (Program B still running on Computer B) and then run Program A on Computer A.
I must use expect and I must use a password for ssh to accomplish this.
Here is my try so far (it is not working):
#!/bin/bash
#checks to see if programA is already running
if pidof -x "programA">/dev/null; then
echo "Program A already running"
exit 1
fi
spawn ssh username@{$1}
/usr/bin/expect "assword:"
send "password"
./programB & # run programB in the background
exit
./programA
Here is the script which is supposed to terminate the programs on both computers:
pkill programA
spawn ssh username@{$1}
/usr/bin/expect "assword:"
send "password"
pkill programB
exit
The script to start the programs doesn't work as expected. It starts both Program A and Program B on Computer A. It was also brought to my attention that I need to detach my ssh
session because otherwise when I exit it on Computer B Program B will terminate.
Can someone provide me with the script which does what I want it to do, with explanations where I went wrong?
Thank you in advance.