10

I try to execute a bash script via plink. Script looks something like this:

echo "@ Starting process..."
./bin/process "process.cfg" &
disown %1
echo "@ Done!"

When i execute this script in a terminal on linux, everything works fine. After the "Done!" line I get a command prompt (as expected).

Now when I run this script via plink, the output stops afyer the "Done!" line, but plink won't return to the command prompt and "hangs" until +c.

The script is placed in a file and given to plink with the -m parameter

I tried addind 'logout', 'exit', 'set -e' at the end of the script, but it doesn't help. Also adding -batch, -T or -N to the plink command brought no success.

Any ideas on how to fix this?

user3252141
  • 171
  • 1
  • 1
  • 6

3 Answers3

7

Ok, it seems I had to detach stdout/err from the terminal. In a normal terminal this wouldn't matter ofcourse, but plink remained in a "busy" state because of this.

So, inside my bash script (which executed the command) I had to change:

./bin/process "process.cfg" &

to:

./bin/process "process.cfg" /dev/null 2>&1 &

plink now returns the correct "finished" state at the end of the bash script.

user3252141
  • 171
  • 1
  • 1
  • 6
  • Thanks - I was battling with similar issue trying to start Linux hosted WebLogic from a Windows hosted script. Redirecting output of startWebLogic.sh to /dev/null seems to have fixed it. (upvote) – andyb Jan 28 '15 at 23:55
  • 4
    Is this missing a '>' before the /dev/null? – Oliver Bock Sep 11 '15 at 04:00
  • Hey guys, How to do plink disconnect / logout when my remote script completes? "plink.exe -ssh domain -pw password /home/myscript.sh > output-deploy.txt" – Jose Vieira Neto Nov 23 '16 at 17:18
5

plink.exe -P PORT_NUM -v USERNAME@HOST_IP -pw PASSWD "COMMAND >/dev/null &"

  • & would move your process to the background
  • > /dev/null allows your command run silently by getting stdout/stderr to output to a dummy null device

note: the shell command is wrapped in "double quotations"

Zahra
  • 6,798
  • 9
  • 51
  • 76
0

Plink has a -batch parameter which disable all interactive prompts. It may be what you need here to avoid hanging until ctrl-C.

Cyrille
  • 13,905
  • 2
  • 22
  • 41