0

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.

6
  • 2
    I'm guessing that if the command hangs, it is because it is waiting for the "server". Can you try 'ping'ing the server? If that doesn't work and you have access to PowerShell, try the following: Test-NetConnection server -port 22 If the last line of output from that command is: TcpTestSuccesseded: False then you have a network issue. Commented May 7, 2024 at 22:37
  • Does it output anything? Would it output anything, if you add -v? Commented May 8, 2024 at 5:27
  • Does this answer your question: plink won't return to command prompt? Commented May 8, 2024 at 6:07
  • @iRon Shouldn't be the case with a simple rm command. Commented May 8, 2024 at 7:29
  • 1
    Anyways, it should be easy to exclude PowerShell from the issue by trying the command from a different terminal/console: 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 (&) Commented May 8, 2024 at 8:40

2 Answers 2

1

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

answered May 16, 2024 at 7:32
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered May 13, 2024 at 13:46

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.