JavaRed
JavaRed

Reputation: 708

Remote sudo, execute a command and write output in local terminal

What I try to do, I connect to a remote server as a normal user with sudo right, then sudo to root, and execute a command & see output in my local terminal. I wrote a small script like this:

#!/bin/bash

my_argument=$1
ssh -t username@hostname 'sudo su -; /path_to_my_script $1'

I type the password twice (one for ssh, the other for sudo), but I see nothing in my local terminal, and script looks terminated in remote host. I believe second problem could be resolved by using exit, but I am a little bit confused how I can get this output to my local terminal.

Thanks

Upvotes: 1

Views: 4466

Answers (1)

ArturFH
ArturFH

Reputation: 1787

String inside '' is taken literally. So, you are passing the dollar sign and 1 as a parameter to the script. If you want the string to be interpreted, place it inside "", like:

ssh -t username@hostname "sudo /path_to_my_script $1"

Upvotes: 5

Related Questions