In my script I have the following:
expect -f ./connect.exp &
java -Xmx1024m -Xms128m -cp other.jar
On my connect.exp
#!/usr/local/bin/expect -- #
spawn ssh firstname.lastname@example.org -L 4000:localhost:4000
In my code I have expect doing a establishing a ssh connection and creating a ssh tunneling. Then I leave the process hanging waiting on a loooong sleep.
So I want to kill the process spawned with expect. Therefore I want to get the pid of that process so I can make a kill.
I will consider also a correct answer a solution for the silly handling that I am doing on my connect.exp, that would also result in having my tunnelling.