2

I need to find pid of proccess started in bash script with another program. I use sshpass to enter the password, sshpass start ssh client and that client open sshtunnel to server. Here is examples:

start_tunnel.sh
#!/bin/bash
exec sshpass -p 'passw' ssh -D :port user@$server -o StrictHostKeyChecking=no -f -N
exit

And I start it with subrocess.Popen:

proc = subprocess.Popen('start_tunnel.sh')

The script start just fine, it normally finish and return 0, I can get it PID, but is it possible to get the PID of started sshclient?

3 Answers 3

1

By default proc.pid will return the PID of the shell (ie the parent process). What you're looking for is the PID of the child process (sshpass).

So set shell=False in subprocess.Popen. Documentation is here.

Sign up to request clarification or add additional context in comments.

Comments

0

Just call the sshpass directly from Popen and pass in the shell=False option. Then the direct child will the be the sshpass subprocess. No need for a shell wrapper.

1 Comment

Thanks for unswers guys, if I do this, I get sshpass PID, but is it possible to get PID of sshclient proccess, which spawned by sshpass proccess?
0

Using subprocess.Popen I would simply call the shell=false option.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.