Is this possible in one SSH session? (BASH & PYTHO

2019-09-11 13:35发布

问题:

I'm writing a python script (on a Linux box) that will perform an SSH and run a string of commands on the remote machine (Sun-OS). I'm having trouble getting the remote commands to run and give expected output and I'm not sure if this is even possible.

Depending on the syntax I use, sometimes I get : "ksh: 28317 Segmentation Fault(coredump)"

If this is not possible, but it is using a different method in either python or at the CLI, please let me know.

Thanks!

ssh user@remote_machine "/dvs/dncs/bin/tellDhct -h mempoll/mempoll_lowmem_ips.out | awk '{print $1}' > mempoll/mempoll.macs && /dvs/dncs/bin/tellDhct -h mempoll/mempoll_nonresp_ips.out | awk '{print $1}' >> mempoll/mempoll.macs"

回答1:

Try something like this:

ssh user@remote << EOT
echo "test"
echo "you can put here anything like in a bash script"
echo "and it should work"
EOT