plink.exe "hanging" when used in PowerShell script

I have a script that removes files from a Linux server using PowerShell. The script suddenly stopped working and now it "hangs" when running this command:

$file = "file_path"

plink.exe -pw password account@server "rm $file"

I don't get any error message neither the script finish.

Upvotes: 0

Views: 242

Answers (2)

Dudi Boy
Dudi Boy

Reputation: 4900

I suggest plink.exe is not returning because it oppened some kind of an interactive shell on the linux host...

Therefore waiting on a prompt.

If there was any networking issue, you would get an error after 120 sec.

Suggesting to run the plink.exe command interactively in PowerShell terminal, and see what happens.

Suggesting to inspect the relevant plink.exe documentation, especially options -v and -batch

Upvotes: 1

Dennis
Dennis

Reputation: 1792

To at least avoid the command hanging your script, you could add a time-out.

$file = 'file_path'
$PlinkArgs = "-pw password account@server ""rm $file"""

Wait-Process (Start-Process plink.exe $PlinkArgs -PassThru).Id -TimeOut 10 #seconds

You might also consider using a try - catch statement as well to kill and log any plink commands that doesn't terminate by them self.

Upvotes: 0

Related Questions