Script via Plink in .bat behaves differently

I have a .bat file on my Windows machine. This .bat file uses plink.exe to connect to an Ubuntu machine and execute an .sh script. However, I get different behaviors on the script depending on how Plink is used:

  1. log onto Ubuntu directly (in person) -- script succeeds

  2. ssh via Bitvise client -- script succeeds

  3. ssh via Plink (by calling plink.exe) and calling script from interactive shell (it's a Ubuntu shell within windows cmd.exe) -- script succeeds

  4. ssh via .bat which then calls Plink -- script fails

The script fails w/ message:

error while loading shared libraries: libCint.so: cannot open shared object file: No such file or directory

Other posts seem to refer to installation/permission issues of libCint.so but I know this is not the case since the script works correctly in other instances as shown above.

Below is the plink.exe line from my .bat file:

plink.exe !plink_ssh_details! myscript

The above script fails when called this way via .bat file; again, note that it succeeds when called directly from the Ubuntu or when I -ssh directly into the Ubuntu via cmd.exe (using plink.exe) or Bitvise client. Any help would be appreciated.


In the other cases, you are using interactive sessions.

While the Plink uses non-interactive session by default, when you specify a command on its command-line.

Your script probably relies on some environment variables (like PATH) being set specifically.

It's quite probable that the variables are set only for interactive sessions. Probably because they are modified in a startup script that is executed (sourced) for the the interactive sessions only.

Solutions are:

  • Correct the startup scripts to modify the variables unconditionally (even for non-interactive sessions).

  • Modify the script not to rely on environment variables.

    Or you can source the profile script, see Unable to run shell script with ktutil command from Windows using PLINK.

  • Force the Plink to use the interactive session using the -t switch

    This is not a recommended solution, as using the interactive session to automate a command execution can bring you nasty side effects. See for example Is there a simple way to get rid of junk values that come when you SSH using Python's Paramiko library and fetch output from CLI of a remote machine?


Some more obscure SSH servers can also behave differently when "exec" channel is used to execute the command. See Executing command on Plink command line fails with "not found".