Search code examples
pythonshellunixpexpect

is it possible to execute a bash script on remote machine using python pexpect


I connected to remote system using Python Pexpect, Now I want to execute some script(available on remote machine) on remote system is it possible?


Solution

  • Yes, you can do it by adding \n between the commands

    Or,

    child = pexpect.spawn('ssh MACHINE')
    
    child.sendline('command1')
    child.sendline('command2')
    child.sendline('command3')
    
    child.close()
    

    I would advice you reading this http://pexpect.readthedocs.io/en/stable/overview.html