Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to execute ls after opening a new Guake tab and logging into postgres.

guake -n guake -e 'sudo -i -u postgres && ls'

The command successful opens a new tab then prompts me for my password and logins into postgres, but it does not execute ls once in postgres.

How can I achieve this?

share|improve this question
up vote 1 down vote accepted

Did you check manual page for sudo? The third synopsis example shows

sudo [...] [-u user name ] [VAR=value] -i | -s [command] 

the command part is the thing you are looking for. It is the command that is executed after changing user to the required one.

This fits exactly into your example like this:

sudo -u postgres -i ls

joining everything together with your original task:

guake -n guake -e 'sudo -u postgres -i ls'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.