Domanda

Okay I'm sure this has been asked before but the life of me I can't find an answer (it's not possible / how to do it).

I have a shell script script.sh which runs a command on a remote server using:

    ssh -t [SERVER] "[COMMAND TO BE EXECUTED REMOTELY]"

This works fine including if the command contains sudo.

However, sometimes I redirect the output of this script.sh and of course if the remote command contains sudo the sudo password prompt is redirected also.

Is there a way to:

    ./script.sh > script.out

and still get the remote sudo password prompt on the terminal?

Passing the sudo password on the cli for script.sh is not an option.

Many thanks,

Alasdair.

È stato utile?

Soluzione

You can use tee to duplicate the standard input:

./script.sh | tee script.out

After that you can filter what is output with an awk command

./script.sh | tee script.out | awk '/^Password/ {print;}'
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top