1

Have script which daily reading configs from bunch of network devices utilizing plink.exe. Time by time, some device have stucked internal process which provide backup data and plink instance (and thus whole script) stuck until CTRL+C is pressed. Is there any way to push plink.exe to set timeout for remote operations? Now only SSH protocol layer timeout are reported by plink.exe, but this is not my case because SSH connection and login runs over successfully, but remote command execution stuck whole process.

I cant find anything helpful in plink.exe help

5
  • Would it work if you had a separate process that monitored your plink.exe script and killed it after a period of time rather than relying on plink.exe to do it? If so, would something like this work? stackoverflow.com/questions/53977026/…
    – Quetza
    Apr 5, 2021 at 11:44
  • I am aware of this solution but looking for something more reliable (as killing stucked process is not) Apr 5, 2021 at 13:15
  • Would you consider using something other than plink? Winscp can be similarly scripted and has a timeout option.
    – Quetza
    Apr 5, 2021 at 13:29
  • I wrote feature request to authors of plink, so will see. Know winscp, but prefer small, single purpose, utilities without installing process. Now looking for some putty ports (like Quest putty) with this feature enabled. Apr 5, 2021 at 13:48
  • While not as small as plink.exe, winscp does have a portable exe and I've had good success with the .NET assembly for Powershell for having more control over an sftp-reliant application
    – Quetza
    Apr 5, 2021 at 16:09

3 Answers 3

0

What about to ping the device before you connect with plink. Thanks to this answer I got a perfect function:

set "_ip=localhost"
set "_ip=192.168.1.1"
ping %_ip% -n 1 -4 | find /i "TTL=">nul
if errorlevel 1 (
    echo ping %_ip% failure
    ) else ( 
    echo ping %_ip% success
    )
  • -4 to force using IPv4 (as e.g. ping localhost replies IPv6 with no TTL= output)
  • | find /i "TTL=" as find command raises errorlevel well
  • >nul to suppress undesired output

Just replace the echo ping %_ip% success with your plink commands.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Oct 12, 2022 at 12:42
0

This powershell code start windows process [here ping.exe to easier testing] and terminate it if it does not end until preset time [here 3 seconds - 3000 miliseconds] out.

powershell.exe "Start-Process 'ping.exe' -ArgumentList '127.0.0.1', '-t' -NoNewWindow -PassThru | %% { if(-not $_.WaitForExit(3000)) { $_.Kill() } }"

Its an oneliner to easy use in hybrid batch/ps scripts

-1

There is no plink option for this.

But there are many workarounds, for example if you have have GNU timeout installed

/usr/bin/timeout 2s plink -no-antispoof $me@$host hostname -s
2
  • Downvote, bacuse this question if for plink.exe [windows executable], not a linux one Apr 2, 2023 at 9:19
  • I have cmder installed (on windows), which has "linux toolset" installed. That is one of the ways to deal with life on windows. Apr 3, 2023 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .