Interactive Shell Scripting in OS X
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 92
- Joined: Wed May 29, 2013 1:54 am
- Location: Sydney, Australia
Interactive Shell Scripting in OS X
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...
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
Check the open process command in the docs
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Interactive Shell Scripting in OS X
Monte, it isn't supported on OS X. Someone should fix that...
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Interactive Shell Scripting in OS X
The docs lie
Edit: no they don't... support for OS X was added in version 2.0.
Edit: no they don't... support for OS X was added in version 2.0.
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Interactive Shell Scripting in OS X
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."
"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."
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Interactive Shell Scripting in OS X
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
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
-
- VIP Livecode Opensource Backer
- Posts: 92
- Joined: Wed May 29, 2013 1:54 am
- Location: Sydney, Australia
Re: Interactive Shell Scripting in OS X
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:
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:
Then I get:
Which is the same message I get if I try to do:
Is there a way to do this from inside LiveCode? - or will I have to resort to using a bash script?...
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:
Code: Select all
ssh admin@example.com
Code: Select all
Password:
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
Code: Select all
process is not open for write
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
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).
Code: Select all
put shell("ssh admin@example.com") into field "output"
Re: Interactive Shell Scripting in OS X
StackOverflow to the rescue:
http://stackoverflow.com/questions/7114 ... a-terminal
http://stackoverflow.com/questions/7114 ... a-terminal
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Interactive Shell Scripting in OS X
Monte is always correct. I've been trying to catch him in a mistake for years.icouto wrote:Ok, it seems Monte is correct:
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Interactive Shell Scripting in OS X
lol... tell that to Rebecca
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/
Re: Interactive Shell Scripting in OS X
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
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