[Gambas-user] shell

Rolf-Werner Eilert eilert-sprachen at ...221...
Mon Dec 2 18:14:04 CET 2013


You could allow a certain user to execute a command via the sudo system. 
I've got this here, one of the teachers is able to switch the internet 
on and off for students by applying a script. Normally, only the admin 
is allowed to change the filter chain... A Gambas front-end picks out 
the persons in the current class and feeds the script with their 
terminal data.

Rolf


Am 02.12.2013 17:08, schrieb MinnesotaJon:
> Maybe I'm not understanding the problem, but "sudo" always wants a password,
> right?  In which case you have to feed it a password with the Exec or Shell
> command.  I'm not a shell script expert (just learning), but I assume that
> the string would look like this:
>
> Exec [system.shell, "sudo sh -c 'echo out
> /sys/class/gpio/gpio27/direction'<< EOF\nmypassword\nEOF"]
> where you have already dimensioned and set the value of "mypassword" in your
> code.
>
> If you have dimensioned a variable like "strShellResponseString", you will
> be able to display a response from sudo in your program, if the password is
> incorrect:
> Exec [system.shell, "sudo sh -c 'echo out
> /sys/class/gpio/gpio27/direction'<< EOF\nmypassword\nEOF"] TO
> strShellResponseString
>
> note:  My additional code is a "here document" code block.  "<<" feeds a
> command list to an interactive program or a command, like sudo.  "EOF" means
> end-of-file, but it also terminates input from stdin.  The newline escape
> code "\n" is needed before and after the password variable, to place the
> password where sudo expects it, after a linefeed from stdin, followed by
> another linefeed.  And then the second "EOF" terminates this input, which
> allows sudo to evaluate the password and either execute the sh command, or
> give an error message if the password is wrong.  No extra spaces in all of
> this, or they'll be interpreted as part of the code!
>
>
>
> --
> View this message in context: http://gambas.8142.n7.nabble.com/shell-tp44500p44508.html
> Sent from the gambas-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT
> organizations don't have a clear picture of how application performance
> affects their revenue. With AppDynamics, you get 100% visibility into your
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list