SSH to server, Sudo su - then run commands in bash [duplicate] SSH to server, Sudo su - then run commands in bash [duplicate] shell shell

SSH to server, Sudo su - then run commands in bash [duplicate]


Try

ssh -t $USER@server006.web.com 'sudo -u http grep -i "Exception:" /opt/local/server/logs/exceptions.log | grep -e "|*-*-*:*:*,*|" | tail -1 | awk -F"|" "{print $2}" >> log.log'

Sudo already runs the command as a different user to there's no need to su again.

Only reason to do sudo su is to have a fast way to start a new shell with another user.


You probably want sudo -u instead of sudo su -:

ssh -t $USER@server006.web.com sudo -u http script 


Guess I'm late to the party.My solution:

ssh -t $USER@server006.web.com "sudo cat /etc/shadow"

and replace cat /etc/shadow with your desired program.