Shell Command with Sudo

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Shell Command with Sudo

Justin Sloan-2
Hello All,

I am trying to run a shell() command in revStudio in order to execute some terminal commands as the superuser on a Mac. An Ubuntu terminal will accept the superuser password using a pipe, such as "pass | sudo -S command", but Mac's terminal will not accept the password on the same line.

Is there a way to run multiple commands from a single rev shell() call? Or, can I somehow followup a shell() call with the password?

Thanks,

Justin_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

sims

On Jun 11, 2010, at 12:35 PM, Justin Sloan wrote:

> Hello All,
>
> I am trying to run a shell() command in revStudio in order to execute some terminal commands as the superuser on a Mac. An Ubuntu terminal will accept the superuser password using a pipe, such as "pass | sudo -S command", but Mac's terminal will not accept the password on the same line.
>
> Is there a way to run multiple commands from a single rev shell() call? Or, can I somehow followup a shell() call with the password?

I went to  http://www.mail-archive.com/use-revolution@.../info.html
In the search field I put:    multiple shell commands os x

It returned a few items that might be of help for you, at least worth a try:

-----------
As an alternative solution, one could use multiple shell commands
separated by a semi-colon:

get shell("cd /etc/ ; ls")
-----------
atb,
sims



_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Andre Garzia-3
In reply to this post by Justin Sloan-2
Justin,

I always though you could not pipe passwords into sudo. One way to do this
kind of stuff is to use the "expect" tool.

http://expect.sourceforge.net/

With expect you can automate many command line things.

HTH

Andre

On Fri, Jun 11, 2010 at 7:35 AM, Justin Sloan <[hidden email]>wrote:

> Hello All,
>
> I am trying to run a shell() command in revStudio in order to execute some
> terminal commands as the superuser on a Mac. An Ubuntu terminal will accept
> the superuser password using a pipe, such as "pass | sudo -S command", but
> Mac's terminal will not accept the password on the same line.
>
> Is there a way to run multiple commands from a single rev shell() call? Or,
> can I somehow followup a shell() call with the password?
>
> Thanks,
>
> Justin_______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



--
http://www.andregarzia.com All We Do Is Code.
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

David Bovill-5
Don't think expect is the right way to do this - best would be to use an ssh
key (seem to remember that is how I used to do this back when i was on Linux
with Metacard), or else to write a bash script as a text file and then get
rev to execute that.

On 11 June 2010 16:33, Andre Garzia <[hidden email]> wrote:

> Justin,
>
> I always though you could not pipe passwords into sudo. One way to do this
> kind of stuff is to use the "expect" tool.
>
> http://expect.sourceforge.net/
>
> With expect you can automate many command line things.
>
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Justin Sloan
Thanks to all who replied. With you help and some additional research
I came up with a solution.

Mac OS X bash shell only allows results from commands to be piped in
to another command, including sudo, not plain text. The solution is to
set a bash variable (pw=password) and echo the variable to pipe it
into sudo (echo $pw | sudo -S command). In Rev you must set the
variable and pipe it in on the same shell() call. Like this:

shell("pw=" & tPassword & "; echo $pw | sudo -S command")

Works like a charm, and it's an elegant solution without a lot of
hashed code. I have not tested this on other Unix based systems but
the command should work on any system with bash as the default shell.


Happy coding!
 - Justin


On Fri, Jun 11, 2010 at 6:51 PM, David Bovill <[hidden email]> wrote:

> Don't think expect is the right way to do this - best would be to use an ssh
> key (seem to remember that is how I used to do this back when i was on Linux
> with Metacard), or else to write a bash script as a text file and then get
> rev to execute that.
>
> On 11 June 2010 16:33, Andre Garzia <[hidden email]> wrote:
>
>> Justin,
>>
>> I always though you could not pipe passwords into sudo. One way to do this
>> kind of stuff is to use the "expect" tool.
>>
>> http://expect.sourceforge.net/
>>
>> With expect you can automate many command line things.
>>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Peter Alcibiades
In reply to this post by Justin Sloan-2
Is there a reason you cannot use the NOPASSWD option in sudo?  Maybe this is not how it works in OSX, but what you'd normally do is to edit /etc/sudoers to allow this particular user to perform this particular command with the no password option, and its done.  If you do this, the command can be limited to one with specific options.  For instance, you can allow shutdown with the -h option, but not the -r option.  No-one has to know the root password then and it is not written anyplace.  Yes, you do have to know it to edit /etc/sudoers.
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Richmond Mathewson-2
On 06/12/2010 12:08 PM, Peter Alcibiades wrote:
> Is there a reason you cannot use the NOPASSWD option in sudo?  Maybe this is
> not how it works in OSX, but what you'd normally do is to edit /etc/sudoers
> to allow this particular user to perform this particular command with the no
> password option, and its done.  If you do this, the command can be limited
> to one with specific options.  For instance, you can allow shutdown with the
> -h option, but not the -r option.  No-one has to know the root password then
> and it is not written anyplace.  Yes, you do have to know it to edit
> /etc/sudoers.
>    

This is all very charming, but I wonder how one would
effect this from a standalone on an end-user's machine . . .  :)
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Justin Sloan
Peter,

That is a good suggestion if the application was not meant for mass
deployment. Otherwise each machine's sudoers file would have to be
edited accordingly, which would be a bummer for users that do not know
how to do so. And that is likely the majority of Mac users. I would
venture to say that the majority of Mac users never even opened the
Terminal.

The solution is elegant, I believe, in that it will work on any Mac OS
X machine and takes advantage of Bash' s flexibility with Rev's shell
structure.

Happy coding!
 - Justin


On Sat, Jun 12, 2010 at 12:11 PM, Richmond <[hidden email]> wrote:

> On 06/12/2010 12:08 PM, Peter Alcibiades wrote:
>>
>> Is there a reason you cannot use the NOPASSWD option in sudo?  Maybe this
>> is
>> not how it works in OSX, but what you'd normally do is to edit
>> /etc/sudoers
>> to allow this particular user to perform this particular command with the
>> no
>> password option, and its done.  If you do this, the command can be limited
>> to one with specific options.  For instance, you can allow shutdown with
>> the
>> -h option, but not the -r option.  No-one has to know the root password
>> then
>> and it is not written anyplace.  Yes, you do have to know it to edit
>> /etc/sudoers.
>>
>
> This is all very charming, but I wonder how one would
> effect this from a standalone on an end-user's machine . . .  :)
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: Shell Command with Sudo

Peter Alcibiades
In reply to this post by Richmond Mathewson-2
Richmond Mathewson-2 wrote
This is all very charming, but I wonder how one would
effect this from a standalone on an end-user's machine . . .  :)
You'd have to write an install or first use shell script.  Get the user, then the root password, then write an extra line to /etc/sudoers.  The advantage, though it will not matter to many, is that you don't store the password in the app and don't have to supply it at each use of the commands, and that you have restricted your privileges to one named user and one variant of one command.  

Justin's solution is very nice, agreed.  Probably more practical and certainly easier to do.  But, you do end up storing the password, and what commands can be executed is not limited, nor is which user limited.  

Or maybe this is wrong?  That is what the effect, I think, would be on Debian, which ships without sudo built in.  Maybe these distros that ship with sudo are preconfigured to allow any user to sudo with their own login password?  In which case they can do sudo su -?  I don't much like that idea either, that cannot be surely?