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.
2 Answers 2
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
Comments
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.
Test-NetConnection server -port 22If the last line of output from that command is:TcpTestSuccesseded: Falsethen you have a network issue.-v?rmcommand.plink.exe -pw password account@server "rm file_path". If it concerns a variable path, I suspect a special character in the path as e.g. a space ... or an ampersand (&)