I have two VMs, Vm-A & Vm-B.

I have two scripts: one in VM-A & another in VM-B

VM-A has a bash script which gets CPU% every second & saves it to a variable $cpu.

VM-B has a bash script which does some actions according to CPU%

I want to execute the script on VM-B (bash scriptb.sh arg1) every second with $cpu from VM-A

How can I do this using ssh or php?

I tried searching a lot on google but could not get anything that I can understand.

  • so, what did you find, and what did you not understand Aug 28, 2022 at 14:10
  • it´s hard to write something you understand if chances are our text are very similar to those you did not understand, since you leave us no clue what you would in fact understand. Aug 28, 2022 at 14:11
  • @MarcusMüller all i found that executing script to vm b from vm a but the examples are with script of vmb located in vm a
    – ph3ro
    Aug 28, 2022 at 14:12
  • again, not clear what you not understand there Aug 28, 2022 at 14:12
  • in above post arg1 = $cpu value from vm-a
    – ph3ro
    Aug 28, 2022 at 14:13

1 Answer 1


Write the scripts to use stdin and stdout.

Then on machine A do:

script-A | ssh machine-B script-B

Or on machine B do:

ssh machine-A script-A | script-B

To give temporary access to keys you can log-in to machine-A using ssh -A. Ensure that you trust machine-A. If not then you can use a sand-boxed account on B, and a custom key that gives access to this sand-boxed account only. You can even configure ~/.ssh/authorized_keys of this account, to run the script and only the script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .