Interactive Shell Scripting in OS X

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Interactive Shell Scripting in OS X

Post by icouto » Thu Nov 07, 2013 9:18 am

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...

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Interactive Shell Scripting in OS X

Post by monte » Fri Nov 08, 2013 8:35 am

Check the open process command in the docs
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Interactive Shell Scripting in OS X

Post by jacque » Fri Nov 08, 2013 10:22 pm

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

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Interactive Shell Scripting in OS X

Post by monte » Fri Nov 08, 2013 10:42 pm

The docs lie ;-)

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/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Interactive Shell Scripting in OS X

Post by jacque » Sat Nov 09, 2013 12:09 am

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."
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Interactive Shell Scripting in OS X

Post by monte » Sat Nov 09, 2013 1:30 am

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/

icouto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Wed May 29, 2013 1:54 am
Location: Sydney, Australia

Re: Interactive Shell Scripting in OS X

Post by icouto » Sat Nov 09, 2013 8:15 am

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:

Code: Select all

ssh admin@example.com
...and wait to enter your "password" at the password prompt:

Code: Select all

Password:
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:

Code: Select all

process is not open for write
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?... :(

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Interactive Shell Scripting in OS X

Post by monte » Sat Nov 09, 2013 8:39 am

LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7230
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Interactive Shell Scripting in OS X

Post by jacque » Sat Nov 09, 2013 8:25 pm

icouto wrote:Ok, it seems Monte is correct:
Monte is always correct. I've been trying to catch him in a mistake for years. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: Interactive Shell Scripting in OS X

Post by monte » Sat Nov 09, 2013 9:45 pm

lol... tell that to Rebecca ;-)
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

rjay
Posts: 2
Joined: Tue Nov 12, 2013 5:07 pm

Re: Interactive Shell Scripting in OS X

Post by rjay » Tue Nov 12, 2013 6:20 pm

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

Post Reply

Return to “CGIs and the Server”