Hi. There will be power cut of the whole building several times a year for maintenance of electric devices. So I need a scheduled shutdown of FGT when power cut planned but someone will do overtime work, and I don't want FGT to be shutdown for a long time too.
I have a batch file which launch telnet client then execute a vbscript to sendkeys to the telnet client, it runs well when I log on Windows, but when I put it into the Windows Task Scheduler, it never works.
I also tried the Plink program which is part of PuTTY, it seems that it can't handle the "Do you want to continue? (y/n)" message toward the "exec shutdown" command.
Is there any methods for a scheduled shutdown?
Nominating a forum post submits a request to create a new Knowledge Article based on the forum post topic. Please ensure your nomination includes a solution within the reply.
jiangchundi wrote:I have a batch file which launch telnet client then execute a vbscript to sendkeys to the telnet client, it runs well when I log on Windows, but when I put it into the Windows Task Scheduler, it never works.
Did you add it to the task scheduler like so
[code lang=vb]/c start "" "c:\pathto\batch.bat"
A workaround would be run the batch/vbscript without Windows Task Scheduler, in the vbscript "sleep" some seconds until the shutdown time comes. A better way is PowerShell and SSH.NET Library(http://sshnet.codeplex.com/), something likes:
sleep [int](([DateTime]$ShutdownTime - [DateTime]::Now).TotalSeconds)
$client = New-Object Renci.SshNet.SshClient($hostip,"admin",$passwd) $client.Connect(); sleep 1 if ($client.IsConnected){ $stream = $client.CreateShellStream("Test",0,0,0,0,1000); sleep 1 $stream.Read(); sleep 1
$stream.Write("exec shutdown`n"); $stream.Flush(); sleep 1
$stream.Read(); sleep 1 $stream.Write("n"); $stream.Flush(); sleep 1
...... -----
Sorry I forgot what I have tried exactly, I think the reason of failure is that vbscript's SendKeys needs the telnet client window to be the topmost, but when running from Task Scheduler, there is no telnet window shown at all.
The "exec shutdown" command should have a "y" parameter to bypass the "Do you want to continue? (y/n)" question. so that the "plink -ssh user@host -pw passwd execute shutdown y" will work, and I don't have to add the telnet administrative access.
Select Forum Responses to become Knowledge Articles!
Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.
User | Count |
---|---|
1713 | |
1093 | |
752 | |
447 | |
231 |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.