Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
jiangchundi
New Contributor

Is that possible for a scheduled shutdown?

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?

2 REPLIES 2
gschmitt
Valued Contributor

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"

 

jiangchundi

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.

Announcements

Select Forum Responses to become Knowledge Articles!

Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.

Labels
Top Kudoed Authors