我正在使用此网站(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 "myuser\m"
WAIT "Password:"
SEND "mypass\m"
WAIT ">"
SEND "mycommand\m"
WAIT ">"
答案 0 :(得分:0)
使用Powershell使用连接的csv文件进行编程,我用它来重新编程mfd的
我有一个文件mfd.txt和一个读取它的脚本。
我有一个telnet脚本模板来更改mfd上的设置,powershell脚本为每个mfd创建自定义脚本并设置dns和hostname参数。运行时,会将日志文件通过管道传输到目录中以便稍后检查
脚本如下:
#Process for updating devices quickly using telnet
#Check file exists
c:
cd 'C:\Resources\Telnet'
cls
$fileisthere = $false
$fileisthere = test-path 'C:\Resources\Telnet\mfds.csv'
if ($fileisthere -ne $true)
{
""
Write-Host ("There is no MFD import list C:\Resources\telnet\mfds.csv") | out-file -filepath $logfile -force
""
exit
}
Write-Host ("MFD import List is present")
# for each device in devices:
$mfds = import-csv 'C:\Resources\Telnet\mfds.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:\Resources\telnet\$($tstfile)"
$change1 = get-content $location1
$change1 | ForEach-Object { $_ -replace "dns 1 server", "dns 1 server $($mfddns1)"} | Set-Content $location
$location2 = "C:\Resources\telnet\$($tstfile)"
$change2 = get-content $location2
$change2 | ForEach-Object { $_ -replace "dns 2 server", "dns 2 server $($mfddns2)"} | Set-Content $location
$location3 = "C:\Resources\telnet\$($tstfile)"
$change3 = get-content $location3
$change3 | ForEach-Object { $_ -replace "hostname ether name", "hostname ether name $($mfdhostname)"} | Set-Content $location
$location4 = "C:\Resources\telnet\$($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
}
}