[BATCH] system cannot find file specified - zie pingmodem

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Takkie
  • Registratie: December 2003
  • Laatst online: 17-06 21:59
De afgelopen weken heb ik enorme last van een slechte verbinding bij UPC. :(
Om hen van de juiste info te kunnen voorzien wil ik enkel batch files maken die logs maken.
Het wil me alleen niet helemaal lukken. Nou moet ik erbij zeggen dat ik tamelijk nieuw ben bij batch ''scripting" (gisteren begonnen), maar deze simpele batch wil maar niet lukken.

Hieronder een script dat elke 30 seconde moet pingen naar mijn DNS bij UPC en naar mijn modem.
De replies of time-outs worden opgeslagen en weggeschreven met datum en tijd in een text bestand.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@ECHO OFF&& PUSHD&& SETLOCAL ENABLEDELAYEDEXPANSION&& SETLOCAL ENABLEEXTENSIONS

::  R. Langenberg | Sunday 22/09/2012   version: 1
::  This batchfile pings your DNS and modem every 30 seconds and logs the results.
::  Please set your DNS and modem IP adresses below
SETLOCAL&& set dns=217.46.228.196
SETLOCAL&& set modem=192.168.0.1
SETLOCAL&& set local=127.0.0.1

::  Begin
:AGAIN
CALL :time
ECHO Starting run on %date%  %now%

CALL :pingdns
CALL :pingmodem
CALL :logresults

ECHO End of this run. Next run in 29 seconds...&& ECHO.
SLEEP 29
GOTO AGAIN

:: The ECHO command below indicates an error in the above code when executed.
ECHO ERROR - ERROR - ERROR - ERROR
ENDLOCAL
SLEEP 30

:time
FOR /F "tokens=*" %%T in ('TIME /T') do SET now=%%T
GOTO :EOF

:pingdns
ECHO Pinging your DNS at %dns% with 32 bytes
FOR /F "tokens=1,2,3,5 delims= " %%A in ('PING %dns% -n 1 ^| FINDSTR /I "Reply Request"') do SET ping1=%%A %%B %%C %%D
ECHO %ping1%
GOTO :EOF

:pingmodem
ECHO Pinging your modem at %modem% with 32 bytes
FOR /F "tokens=1,2,3,5 delims= " %%G in ('PING %modem% -n 1 ^| FINDSTR /I "Reply Request"') do SET ping2=%%G %%H %%I %%J
ECHO %ping2%
GOTO :EOF

:logresults
ECHO Logging results to file ..^\results.txt
ECHO %date% %now%   %ping1% %ping2% >> results.txt
ENDLOCAL
GOTO :EOF

::  END


Waar het stuk loopt is bij het label pingmodem, op regel 40.
Zoals het nu staat geeft command de foutmelding "The system cannot find the file specified".
Wanneer ik het %modem% wijzig naar %local% werkt het evenmin. Maar het werkt weer wel wanneer er %dns% staat. |:(
Ik zie niet waar ik een fout heb gemaakt en staar me eigen blind op die ene regel.

Wie kan me op de fout wijzen? Uiteraard zijn tips en tricks welkom!
ter info: ik draai Win7 Ultimate x64 SP1. In de map van het script is ook sleep.exe aanwezig.

Acties:
  • 0 Henk 'm!

  • lordsnow
  • Registratie: Maart 2000
  • Laatst online: 19:55

lordsnow

I know nothing

Deze BAT werkt gewoon bij mij (vanaf de desktop), geen foutmeldingen.

[ Voor 93% gewijzigd door lordsnow op 23-09-2012 16:22 ]


Acties:
  • 0 Henk 'm!

  • Turdie
  • Registratie: Maart 2006
  • Laatst online: 20-08-2024
UPC hoort dit soort dingen zelf te kunnen zien, als je verbinding echt slecht is verschijnen er fouten in je modem.Snap dus niet echt waarom UPC deze logging nodig heeft.

[ Voor 19% gewijzigd door Turdie op 23-09-2012 16:24 ]


Acties:
  • 0 Henk 'm!

  • Takkie
  • Registratie: December 2003
  • Laatst online: 17-06 21:59
@Lordsnow
Sleep is inderdaad een utility dat ik ergens had gedownload en eigenlijk niets anders dan de oude sleep dat bij Windows XP zat.
Thanks voor het testen. Gek genoeg heeft het eerder vandaag wel goed gedraaid op dit systeem.
Ben nu vmware player aan het binnen halen om te zien of het daar wel mee werkt.
Ik zal wel laten weten of het in XP is gelukt

@shadowman12
Bedankt voor het meedenken, maar de gemiddelde helpdesker (ben er zelf ook één) begint met basis checks en zegt vervolgens een monteur aan te sturen. Die vervangt het modem en loopt weg. Heb al 2 swaps gehad.

Verder iemand nog tips of opmerking voor de batch zelf?

Acties:
  • 0 Henk 'm!

  • lordsnow
  • Registratie: Maart 2000
  • Laatst online: 19:55

lordsnow

I know nothing

Wordt er wel een results.txt bestand aangemaakt in de map waar alles staat? Of anders de BAT uitvoeren als Admin?

Acties:
  • 0 Henk 'm!

  • Remco
  • Registratie: Januari 2001
  • Laatst online: 14:44
En als je nu eens %modem% wijzigt in je ip-adres van je modem? Werkt het dan wel?

The best thing about UDP jokes is that I don't care if you get them or not.


Acties:
  • 0 Henk 'm!

  • Takkie
  • Registratie: December 2003
  • Laatst online: 17-06 21:59
@Lordsnow
Het bestand results.txt is al aanwezig en wordt ook aangevuld als ik alleen de dns ping laat wegschrijven.
Uitvoeren als admin lost het helaas niet op. Opmerkelijk is dat ik bij de eigenschappen niet kan aangeven dat het altijd met admin-rechten moet draaien.
Overigens heb ik het nog niet in Windows XP kunnen testen. Ben even m'n schijfje kwijt :S

@Remco
Dat mag helaas niet helpen. Ook 127.0.0.1 had ik al getest.


Om het geheel nog vreemder, nu lukt het helemaal niet meer om het script te draaien.
Het label :now wordt gewoon gedraaid.
Bij het label :pingdns geeft het nog de echo weer, maar de for geeft een foutmelding
The process tried to write to a nonexistent pipe.

Misschien is het beter als ik stop voor vandaag. :/

Acties:
  • 0 Henk 'm!

  • Turdie
  • Registratie: Maart 2006
  • Laatst online: 20-08-2024
Wellicht heb je hier wat aan:

Dit maakt geen log aan, maar je kunt wel gewoon de output copy/pasten en opsturen naar ze.

Stappen:
Collect HostName argument from the command line
Determine Fully Qualified Domain Name of Hostname
Write Heading info and enter into an infinite loop which will Colorize the console output line depending on the ping response time result
Infinite Loop:
Use get-date to create a formatted timestamp for the ping operation
Attempt to PING the specified hostname
Use [STRING]::FORMAT to create a formatted string for the results
Response Time <= 10ms : use white backround and green foreground
Response Time > 10ms : use cyan background and blue foreground
Time-Out : use yellow background and red foreground
Sleep for 1 second
Repeat forever


PowerShell:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
##############################################################################
## PingMon.ps1
##
## Original Script by Kahuna at PoshTips.com - 11/19/2009
##
## Maintenance (most recent updates at top):
## Date        By   Comments
## ----------  ---  ----------------------------------------------------------
## 11/19/2009  KPS  new script
##
##############################################################################
$scriptUsage = @"
==============================================================================
 SCRIPT  : $psScriptName
 AUTHOR  : $psScriptAuth
 VERSION : $psScriptDate
==============================================================================
 PURPOSE:
    powershell script to run a coninuous ping against a given host
    and display time-stamped response times to the console with
    color highlighting for high response times or time-outs
 
 USAGE:
 
    PingMon hostname [-?|-H]
 
    - From the PowerShell command-line, invoke the script, passing a single
      hostnames argument
  FLAGS:
    -? or -H  = Display this help
 
  EXAMPLE:
              ./PingMon server1
 
==============================================================================
"@
 
Set-PSDebug -Trace 0
$script:recCount = 0
 
function ShowUsage([string]$message=""){
    $message
    $scriptUsage
    exit
    }
 
function DoPing ([string]$hostname){
    #$erroractionpreference = "SilentlyContinue"
    $hostname = $hostname.trimend(".")
 
    $fqdn = [System.Net.Dns]::GetHostEntry($hostname).HostName
 
    write-host "Date                 Status  ResponseTime   Host (IP)" -foregroundcolor cyan -backgroundcolor darkblue
    write-host "-------------------  ------  -------------  ------------------------------------" -foregroundcolor cyan -backgroundcolor darkblue
    #          "YYYY-MM-DD_HH:MM:SS  OK      9999999ms      Host (xxx.xxx.xxx.xxx)"
    #          "YYYY-MM-DD_HH:MM:SS  FAIL    TIMEOUT        Host (xxx.xxx.xxx.xxx)"
 
    $ping = new-object System.Net.NetworkInformation.Ping
    while(-1) {
 
        $ts = get-date -uformat %Y-%m-%d_%H:%M:%S
        $reply = $ping.send($hostname)
        if ($reply.status -eq "Success"){
            $x = [string]::Format("{0}  {1}  {2,7:D}ms      {3} ({4})",
                $ts,
                "OK    ",
                $reply.RoundtripTime,
                $fqdn,
                $reply.Address.ToString())
 
        if ($reply.RoundtripTime -le 10) {
            write-host $x -foregroundcolor darkgreen -backgroundcolor white
            }
        else {
            write-host $x -foregroundcolor Blue -backgroundcolor cyan
            }
        }
    else {
            $x = [string]::Format("{0}  {1}  {2}        {3} ({4})",
                $ts,
                "FAIL  ",
                "TIMEOUT",
                $fqdn,
                "")
            write-host $x -foregroundcolor red -backgroundcolor yellow
            }
        sleep 1
        }
    }
 
######################################################
## MAIN
######################################################
if ($args.count)
    {
    # Process command-line flags
    foreach ($item in $args)
        {
        if ($item -like "-*")
            {
            switch ($item)
                {
                "-H" {ShowUsage;}
                "-?" {ShowUsage;}
                default {ShowUsage "ERROR: $item is invalid!";}
                }
            }
        }
    # Process non-flag arguments
    foreach ($item in $args) {
        if ($item -notlike "-*") {
            DoPing $item
            }
        }
    }
else
    {
    ShowUsage "ERROR: This script requires arguments"
    }


Bron: http://poshtips.com/2009/...hell-ping-monitor-script/

[ Voor 11% gewijzigd door Turdie op 23-09-2012 18:45 ]


  • Takkie
  • Registratie: December 2003
  • Laatst online: 17-06 21:59
Gisteren en vandaag nog eens een kijkje genomen naar de script en ben blij dat ik een stap heb genomen in deze richting, baal er alleen van dat het ene moment wel en het andere moment niet werkt.
Dus, dag batch, hallo... tjah, zeg het maar. Iemand tips voor de volgende stap in de wereld van dit soort scripts?
Pagina: 1