tst10 telnet脚本持续运行



我正在使用此网站(http://npr.me.uk/scripting.html)连接到telnet并运行命令。它会给我一些信息。我需要每4秒得到一次这个信息。我该怎么做?现在它运行,但每次都会重新连接,所以我必须等待它打开连接,这需要4秒以上的时间。蝙蝠文件:

echo off
cls
if exist r1.txt del r1.txt
if exist r2.txt del r2.txt
tst10.exe /r:stats.txt /o:r1.txt /m
for /f "skip=30 tokens=*" %%A in (r1.txt) do echo %%A >> r2.txt
del r1.txt
start r2.txt

和统计文件:

192.168.xxx.xxx
WAIT "login:"
SEND "myuserm"
WAIT "Password:"
SEND "mypassm"
WAIT ">"
SEND "mycommandm"
WAIT ">"

使用Powershell通过连接使用csv文件进行编程,我正在使用它来重新编程mfd的

我有一个mfd.txt文件和一个在.中读取它的脚本

我有一个telnet脚本模板来更改mfd上的设置,powershell脚本为每个mfd创建自定义脚本,并设置dns和主机名参数。运行时,日志文件通过管道传输到一个目录中,以便稍后检查

脚本如下:

#Process for updating devices quickly using telnet
#Check file exists
c:
cd 'C:ResourcesTelnet'
cls
$fileisthere = $false
$fileisthere = test-path 'C:ResourcesTelnetmfds.csv'
if ($fileisthere -ne $true) 
       { 
        ""
        Write-Host ("There is no MFD import list C:Resourcestelnetmfds.csv")  | out-file -filepath $logfile -force
        ""
        exit 
        }
        Write-Host ("MFD import List is present")

# for each device in devices:
$mfds = import-csv 'C:ResourcesTelnetmfds.csv'
foreach ($mfd in $mfds) 
{             
#   ping device and check for response
$mfdname = $mfd.name
$mfdip = $mfd.ipaddress
$mfddns1 = $mfd.dns1
$mfddns2 = $mfd.dns2
$mfdhostname = $mfd.serial
""
Write-Host ("Updating device $($mfdname) on IP address $($Mfdip) ")
"" 
("Updating device $($mfdname) on IP address $($Mfdip) ")      |  out-file -filepath $logfile -Append -force
if(!(Test-Connection -Cn $mfdip -BufferSize 16 -Count 1 -ea 0 -quiet))
        {         
        Write-Host ""
        Write-Host ("MFD $($mfdname) is offline or not at this address")
        Write-Host ""                                                         
        ""                                                    |  out-file     $logfile -Append -force
        ("MFD $($mfdname) is offline or not at this address") |  out-file $logfile -Append -force
        ""                                                    |  out-file $logfile -Append -force
        }
else
        {
       #find replace script
# Device is present and add to script header
        $tststring = "$($mfdip) 23"
        $tstfile = "$($mfdname)-$($mfdip).txt"
        $tstlogfile = "$($mfdname)-$($mfdip).log"
        $tststring | out-file $tstfile -force
        type dns.txt >> $tstfile
        $location1 =  "C:Resourcestelnet$($tstfile)"
        $change1 = get-content $location1
        $change1 | ForEach-Object { $_ -replace "dns 1 server", "dns 1 server $($mfddns1)"} | Set-Content $location
        $location2 =  "C:Resourcestelnet$($tstfile)"
        $change2 = get-content $location2
        $change2 | ForEach-Object { $_ -replace "dns 2 server", "dns 2 server $($mfddns2)"} | Set-Content $location

        $location3 =  "C:Resourcestelnet$($tstfile)"
        $change3 = get-content $location3
        $change3 | ForEach-Object { $_ -replace "hostname ether name", "hostname ether name $($mfdhostname)"} | Set-Content $location
        $location4 =  "C:Resourcestelnet$($tstfile)"
        $change4 = get-content $location4
        $change4 | ForEach-Object { $_ -replace "devicename name", "devicename name $($mfdhostname)"} | Set-Content $location

        # Create variables for update
        Write-Host ("Updating $($Mfdname) on IP Address $($mfdIP) ")
        $parameter1 = "/r:$($tstfile)"
        $parameter2 = "/o:$($tstlogfile)"
        #& cmd tst10 $parameter1 $paremeter2
        write-host ("$($tstfile)  $($tstlogfile)")

        new-item $tstfolder -Type directory
        move-item $tstfile $tstfolder
        move-item $tstlogfile $tstfolder -ErrorAction SilentlyContinue
        }

}

最新更新