yuni1988
Contributor
Contributor

Difference between running shell script through PowerCLI or interactively

Jump to solution

I'm experiencing some odd issues where I have two different shell scripts and if I run them directly in the terminal they work as expected, but if I run them with PowerCLI command:

invoke-vmscript -VM UBUNTU-20.04 -scriptText "bash myScript.sh" -GuestUser xxx -GuestPassword yyy

then the execution fails after a while (differently on each script, but in both cases the script executes at least partially).

I'm new to PowerCLI, so there is probably some logic behind this behavior that I am not aware of.

First script runs a self-extracting 7z archive with wine.

If I run it interactively it is extracted as expected and then the extractor app closes.

If I run it through the PowerCLI, then the files are extracted (I can see them), but the extractor never finishes execution (process remains running, I can see it in wine TaskMgr).

Second shell script runs a python script with some proprietary API function calls.

If I run it interactively the script works as expected, runs the proprietary software and connects to it.

If I run it through the PowerCLI, then it opens the proprietary software, but then the script fails as it can not connect to this software.

I'm aware that this is a bit cryptic, and details wouldn't help much either, but it's just to show that the first script is not the only one causing issues under PowerCLI.

I'm using the same user account in both cases (interactively and through PowerCLI).

Both the self-extracting archive and the proprietary app are Windows applications that are running through wine.

Seeing the GUI in the first example would probably resolve this quickly, but I am not aware of any way to start a script & be able to see the GUI of processes it spawns.

Can you point me to any material that explains what differences I can expect when using PowerCLI, compared to interactive execution?

Or how I can reproduce the exact way in which these commands are executed with invoke-vmscript?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

I suspect it might be the type of terminal.

The Invoke-VMScript cmdlet starts a session under the vmtoolsd service.

That process uses a TTY and you don't have an X-session.

You might try to start an xvfb (virtual framebuffer X Server), but I have no experience with that I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership

Without seeing the actual errors you are getting, it is hard to analyse what is happening.

You might also try to add some verbosity to the script and/or commands.

Are the scripts by any chance failing after 5 minutes?

Then you might be experiencing a timeout.

Try changing or disabling the web operations timeout with the Set-PowerCLIConfiguration cmdlet and the WebOperationTimeoutSeconds parameter.

Be aware that this setting only takes effect on the next run.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
yuni1988
Contributor
Contributor

The timeout doesn't seem to be the problem, as I observed similar effects also when starting these commands in the background (so that the command returns immediately).

I have enabled infinite timeout just in case and it doesn't make any difference.

After some additional research on case 2 I have noticed that wine crashes soon after it has started with the following error:

wineCrash.png

This does not happen when running the same script directly from the VM.

0 Kudos
LucD
Leadership
Leadership

The majority of those errors seem to be Wine related.
Can you run an application that obviously requires Wine functionality in a background job?


I'm not very versed in Wine, but I suspect that might be the cause of the issues you are seeing.
That app tries to open a Window, while there is no GUI environment (Wine in this case) present.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
yuni1988
Contributor
Contributor

I can't run it in the background - if I change that, I change what I am trying to test (in this case testing if a specific script runs OK).

As the error message suggests, there is the difference in the DISPLAY environment variable if I run it through PowerCLI (comes out empty) or interactively (has value ":0").

I found a somewhat related post here:

DISPLAY env var for linux guest

but in this case the user is not trying to use the PowerCLI, so I can not directly apply the solution.

X-server is obviously running if I check it interactively, but for some reason the script started through PowerCLI does not see it.

Any idea how to proceed? How does this work under the hood? How is the process started?

I have full access to the VM, so if there is some configuration necessary, I can do it, but I need more information to know where to start.

0 Kudos
LucD
Leadership
Leadership

I suspect it might be the type of terminal.

The Invoke-VMScript cmdlet starts a session under the vmtoolsd service.

That process uses a TTY and you don't have an X-session.

You might try to start an xvfb (virtual framebuffer X Server), but I have no experience with that I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
yuni1988
Contributor
Contributor

Running the problematic scripts with xvfb-run has resolved both issues.

Thanks for the tip and your time! Smiley Happy

0 Kudos