Page 1 of 1
Interactive Shell Scripting in OS X
Posted: Thu Nov 07, 2013 9:18 am
by icouto
It seems the only way to run a unix command on OS X from LiveCode is to use the shell() function, right?
Unfortunately, shell() does not seem to allow for interactive commands that require user input - i.e., via stdin - such as starting an ssh session, or running a command with sudo (both of these usually require the user to provide a password). The "open process" command seems to support full-on interactive scripting, but is not available on OS X!...
I run several servers, and need to do certain checks on them regularly, everyday. These checks are usually done by ssh-ing to the servers, and then running several tools as a local superuser - using sudo. I need to automate this task, and thought that LiveCode would be great for this, but perhaps I've hit a wall...
Re: Interactive Shell Scripting in OS X
Posted: Fri Nov 08, 2013 8:35 am
by monte
Check the open process command in the docs
Re: Interactive Shell Scripting in OS X
Posted: Fri Nov 08, 2013 10:22 pm
by jacque
Monte, it isn't supported on OS X. Someone should fix that...
![Wink ;)](./images/smilies/icon_wink.gif)
Re: Interactive Shell Scripting in OS X
Posted: Fri Nov 08, 2013 10:42 pm
by monte
The docs lie
Edit: no they don't... support for OS X was added in version 2.0.
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 12:09 am
by jacque
I think this is the roadblock:
"Note: On OS X systems, you can use the open process command to start up an application, but not a Unix process. To work with a Unix process, use the shell func instead."
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 1:30 am
by monte
Well I don't believe that's right. Try this:
Code: Select all
on mouseUp
open process "ls" for read
read from process "ls" until eof
put it
end mouseUp
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 8:15 am
by icouto
Ok, it seems Monte is correct: you *can* use "open process" in OS X - the docs need to be updated.
I'm still stuck, however. Let's say, for instance, that I want to script an ssh connection to server "example.com", as user "admin", using password "password". In the Terminal you'd use the command:
...and wait to enter your "password" at the password prompt:
This does not look like something that can be scripted from within LiveCode with either open process or shell. If I try:
Code: Select all
on mouseUp
open process "ssh admin@example.com" for text update
read from process "ssh" until ":"
write "password" to process "ssh"
if it is empty then put the result into field "output"
else put it into field "output"
end mouseUp
I get the following into my "output" field:
I guessed that it wants me to use the original string I used to open the process to identify it, so I tried also:
Code: Select all
on mouseUp
open process "ssh admin@example.com" for text update
read from process "ssh admin@example.com" until ":"
write "password" to process "ssh admin@example.com"
if it is empty then put the result into field "output"
else put it into field "output"
end mouseUp
Then I get:
Code: Select all
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).
Which is the same message I get if I try to do:
Code: Select all
put shell("ssh admin@example.com") into field "output"
Is there a way to do this from inside LiveCode? - or will I have to resort to using a bash script?...
![Sad :(](./images/smilies/icon_sad.gif)
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 8:39 am
by monte
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 8:25 pm
by jacque
icouto wrote:Ok, it seems Monte is correct:
Monte is always correct. I've been trying to catch him in a mistake for years.
![Smile :)](./images/smilies/icon_smile.gif)
Re: Interactive Shell Scripting in OS X
Posted: Sat Nov 09, 2013 9:45 pm
by monte
lol... tell that to Rebecca
![Wink ;-)](./images/smilies/icon_wink.gif)
Re: Interactive Shell Scripting in OS X
Posted: Tue Nov 12, 2013 6:20 pm
by rjay
i am after the same or similar functionality as originally posted -- basically opening a ssh session to devices and servers by clicking on them in a map but i can't seem to get anything but 'process not open for write'. last thing i tried was this ...
on mouseUp
open process "ssh -t -t name@servercom" for text update
read from process "ssh" until ":"
write "password" to process "ssh"
if it is empty then put the result into field "output"
else put it into field "output"
end mouseUp