Executing A Script Using shell

I have created a script that is to be executed on the Mac on which EggPlant is running. The script is restartIMS.sh shown in this listing…

pws-s:Scripts hurricane$ ls -l
total 152
-rws–x--x@ 1 hurricane staff 4570 14 Jan 10:18 restartIMS.sh
-rws–x--x 1 root staff 4570 14 Jan 10:24 restartIMS2.sh
-rwxrwxrwx@ 1 hurricane staff 4570 14 Jan 12:21 restartIMS3.sh
pws-s:Scripts hurricane$

Actually I edit and make changes to restartIMS.sh, and copy to the files; restartIMS2.sh and restartIMS3.sh, to make changes to permissions, etc.

From the command line if I issue the commands…

pws-s:Scripts hurricane$ sudo chmod 4711 ./restartIMS2.shPassword:
pws-s:Scripts hurricane$ sudo chown root ./restartIMS2.sh
pws-s:Scripts hurricane$ sudo /Users/hurricane/Desktop/Eggplant_Testing/CommonUtil.suite/Scripts/restartIMS2.sh

…I successfully execute the script which runs a number rsh commands to restart a UNIX system and places it in a known state (in preparation for GUI testing).

Ideally we want to be able to execute this same script from within SenseTalk. So in the run window I issue the command…

shell(“sudo /Users/hurricane/Desktop/Eggplant_Testing/CommonUtil.suite/Scripts/restartIMS2.sh”)

…I get the return code “result: 1”, which is a generic error and completely uninformative. I am hoping that someone here can give me a clue for the next step in dealing with this issue. The script works when run from the shell prompt, but not from within EggPlant.



My initial thought would be that when you try to do the SUDO its in a new context and so it’s trying to ask for a password through the terminal.

This is tricky to do from a separate process, you either need to use an SSHASKPASS or give your user the ability to execute that command without a password through the /etc/sudoers configuration files.

(It could be something else entirely, but that is a good place to start).

Thanks for the tip. I am still investigating. This is quickly reaching the extremes of my OS/networking expertise. Here is what I have done so far…

#1: ssh-keygen -t rsa
This created a key file at ~/.ssh/id_rsa

#2: As root I added the following lines to /etc/ssh_config…

Host *
RSAAuthentication yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
IdentityFile ~/.ssh/id_rsa

I rebooted the Mac and tried again, but I got the same result as in my first post. I am guessing what I have posted here is part of the puzzle but not the full set of pieces.

I am returning to Google for clues, but any tips provided here would be hugely appreciated. I really want to get past this techical block and get back to coding our integration tests.


I was given a tip from EggPlant support. I added this line…

Defaults:USER_NAME !authenticate

…to /etc/sudoers. This resolved the immediate issue and Eggplant had permission to execute the script (no error value returned).

However, this merely allowed me to peel one layer from the onion and now I am looking at the next problem.

The script that is executed works perfectly when launched from the command line. It makes a series of rsh commands that look like this…

rsh -l root ‘echo “STEP 1: LOADING LATEST” >>& /tmp/conout.txt’

What I do is leave this command running on the target machine (…

tail -f /tmp/conout.txt

…and when this is done I will see “STEP 1: LOADING LATEST” displayed by the tail command.

Now, when I execute a command like this…

rsh -l root ‘nohup /some/where/doSomething >>& /tmp/conout.txt &’ < ./rootPassword.txt

…which I know will produce both console output AND error output I will see addition text produced by the tail of the file. In other words when I launch the script which sends a series of rsh commands to the unit under test from the Mac I will see all text (echos, console output and error output) appear in the output file.

HOWEVER… When the very same script is launched with the EggPlant shell command in EggPlant two things happen…
#1: I only see the echo output appear in conout.txt.
#2: The system is clearly not affected as it should be and is when the script is executed from the command line. My script reboots the system as few times and NONE of this is happenning when the script is launched from EggPlant.

Now the primary issue I need to resolve is why I am not seeing the console output and error output in conout.txt. There is likely some useful information in this uncaptured text which will tell me what the script is not effective.

I am thinking this has sometime to do with the type of output redirection used, but thinking this would only apply to the unit under test and have nothing to do with the script being executed on the test host Mac.

Any ideas? Has anyone dealt with these issues before? I am not sure what I would Google in this case. It really appears to be something EggPlant related.



All eggPlant is doing in this situation is passing the command off to the shell to be run – it has no control beyond that and it’s not being run inside eggPlant. There is either something wrong with your syntax or there is a permission issue of some sort. You might try breaking up what your’re trying to do into smaller chunks and try executing pieces of it via the shell command to see what happens. Maybe that will reveal where the problem lies.

There is either something wrong with your syntax or there is a permission issue of some sort.

I don’t think syntax is an issue. I can issue the exact same command at the prompt as I do the the SenseTalk shell command, and when I do it runs without issue and completes as expected. But when I issue that command from within the SenseTalk shell command it runs and “completes” but doesn’t do what it should.

I think you are onto something in regards to the permission idea. The question is what kind of permission differences might there be between the command line and the SenseTalk shell? It may be more like what kind of a shell the command is executed in. Using “ps -p $$” (just Googled that little trick) I confirmed I am using the bash shell at the command line.

Question #1: So my question is… What kind of shell is used by the SenseTalk shell command?

I was considering trying a command other than the shell command and I came across the “open process” command in the SenseTalk documentation.

Question #2: Is the “open process” command a valid method to launch a script from withing EggPlant? The examples in the Sensetalk documentation are rather limitted. Do you have any addition examples? I am not having any luck with Google. I have been trying the command and I am getting a “STProcessException: launch path not accessible” error which I am trying to understand (aaaahhhhh… the mysteries of OS X).

Thanks in advance for any assistance you can provide.


There are precious few good examples of how to use “open process”. I found a few and put together the follow bit of code…

open process "#1" with options (environment: (CWD:"/"))
put "result:  " & result()
put "cd " & FileWrite.getProjectPath() into changeDirectory
put "changeDirectory=" & changeDirectory
write changeDirectory & return to process "#1"
put "sudo ./restartIMS2.sh" into script
put "script=" & script
write script & return to process "#1"
close process "#1"

I got the following output (modified for security purposes)…
changeDirectory=cd /Users/myUserID/Desktop/Eggplant_Testing
script=sudo ./myScript.sh

I am not seeing any of the console output I expect to see on Eggplant, nor is the system undertest being affected by the commands in the script. I suspect I need to capture and display the console output from process “#1” and not just expect it to be displayed on it’s own. I also suspect by the non-effected system under test the script is failing to be executed.

Still looking for more “open process” examples via Google. If anyone can point me to some I would appreciate it. There isn’t much in the SenseTalk docs on the scope of this command.


The shell command is controlled by the global property the ShellCommand. “Put the shellCommand” will show what it’s currently set to – /bin/sh which on Mac OS X is actually bash. You can change it to something else if you like.

Question #2: Is the “open process” command a valid method to launch a script from withing EggPlant? The examples in the Sensetalk documentation are rather limitted. Do you have any addition examples?

Using “open process” gives a lot more control but is also a lot more work than the shell command/function, as you’re discovering. Generally, if all you need is a single command (or one command at a time) you’ll be much better off using shell.

That being said, what you’re trying so far with open process looks like you’re mostly on the right track.

An open process is a two-way communication channel. If you want to see the output from a command, you’ll need to read it. So, for example, after each command that you write, you could do this:

read until end from process "#1" into output
put "Got: " & output

Hopefully that will help you get to the next step! I recognize that there aren’t many examples around that show how to use an open process, which is unfortunate. To that end, here’s a tiny complete example:

open process "#1"
write "ls" & return to process "#1"
read until end from process "#1" into output
put output
close process "#1"

If you succeed in getting your open process script working, please consider posting it back here to help fill the void!

Thanks for the reply. I was consuming too much time with the issue and I abandoned my approach. Now I have the script touch a file in a directory. A daemon shell script sees this and take appropriate action on the SUT depending on which file was touched. It works well.