Announcement

Collapse
No announcement yet.

CMD - Ping/copy

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • CMD - Ping/copy

    Hi,

    I need to write a cmd script which will ping a list of computers in list.txt within domain and if they are online copy folder c:\folder\ to c: on pinged computer. Also I need to make a log which computers was online, which offline and to which there was successfull copy of the folder.

    I had this one for only doing a thing of ping/copy:


    for /f "delims=" %%a in (list.txt) do (
    ping %%a | find /i "bytes=" > nul
    if %ErrorLevel%==0 copy "C:\folder\" "\\%%a\C$\"
    )
    Can anyone tell me how should I do it? to make it do what i wrote at beggining?

    in ex. like this one is makeing an logfile of ping:

    @echo off

    (Set InputFile=C:\list.txt)

    title,Pinging list of computers &color 9e

    ::datestamp
    for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
    for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
    (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
    For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)

    (Set OutputFile=c:\Pinglog.txt)

    If Exist "%OutputFile%" Del "%OutputFile%"

    For /F "eol=;" %%* in ('type "%InputFile%"') do (
    >>"%OutputFile%" (echo.&echo.---------------&(
    echo.%%*;&(ping -a -n 2 -w 750 %%* | Find "."))
    )&echo.done %%*,)


    ::check
    start notepad.exe %OutputFile%


  • #2
    Re: CMD - Ping/copy

    I'd use VBScript personally.

    If no one helps you I'll write a script do it later.
    Andrew

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      Re: CMD - Ping/copy

      Code:
      @echo off & Setlocal
      title,File Copy to a list of computers &color 9e
      
      ::datestamp
      for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
         for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
           (set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p)))
      Set dt=%yy%%mm%%dd%
      
      
      rem (Set OutputFile=outputfile.txt)
       (Set OutputFile=%dt%-outputfile.txt)
      
      >"%OutputFile%" (echo\*** %dt%-%time% *** & echo\ & echo\)
      
      for /f "usebackq delims=" %%a in ("computers.txt") do (
         echo pinging %%a
         >nul (ping -n 2 -w 750 %%a | find /i "TTL=") &&(
         >>"%OutputFile%" 2>&1 (copy "C:\z\*" "\\%%a\C$\" &&(
              echo %%a -done-
              echo\----------------------------------
         ) ||(echo %%a Copy ERROR
              echo\----------------------------------))
         ) ||(>>"%OutputFile%" (
              echo %%a offline 
              echo\----------------------------------))
         echo\---------------------------------------
      )
      
      
      ::check
      start notepad.exe "%OutputFile%"
      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: CMD - Ping/copy

        Used to use an AutoIT script to do the same thing. It'd grab a list of branch server IPs, ping them, copy the results into a log, and then you could select what folder you wanted transferred where, and it would copy it over.
        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: CMD - Ping/copy

          Ye, I was about to use any other program to create a scirpt in VBasic or other, i dont have licence for useing one.

          Thank you Rems, is this possible for this script to copy those "offline" computer names to one place and make script continue working till he copy to all machines?

          I mean..

          for list of computers do

          [IF LIST.TXT is empty exit scipt otherwise continue]

          if computer1 is online copy x:\folder\ to %%a\c$ - delete computer record from file list.txt
          if computer1 is offline - add to the record in list.txt offline

          Comment


          • #6
            Re: CMD - Ping/copy

            Originally posted by ahinson View Post
            I'd use VBScript personally.

            If no one helps you I'll write a script do it later.
            Could you kindly provide such script? look on a topic in my last post what i need more then first desc.
            IF you could do it I would be apriciated.

            Comment


            • #7
              Re: CMD - Ping/copy

              Bump, someone can help me ?

              Comment


              • #8
                Re: CMD - Ping/copy

                Maybe it's me but isn't it easier to copy that file or folder using a login script...
                Marcel
                Technical Consultant
                Netherlands
                http://www.phetios.com
                http://blog.nessus.nl

                MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                "No matter how secure, there is always the human factor."

                "Enjoy life today, tomorrow may never come."
                "If you're going through hell, keep going. ~Winston Churchill"

                Comment


                • #9
                  Re: CMD - Ping/copy

                  I'm not familliar with login script.. ;<

                  Comment


                  • #10
                    Re: CMD - Ping/copy

                    anyone is up to help me??

                    Comment


                    • #11
                      Re: CMD - Ping/copy

                      Are the clients domain joined?
                      Marcel
                      Technical Consultant
                      Netherlands
                      http://www.phetios.com
                      http://blog.nessus.nl

                      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
                      "No matter how secure, there is always the human factor."

                      "Enjoy life today, tomorrow may never come."
                      "If you're going through hell, keep going. ~Winston Churchill"

                      Comment


                      • #12
                        Re: CMD - Ping/copy

                        Originally posted by Girion View Post
                        Thank you Rems, is this possible for this script to copy those "offline" computer names to one place and make script continue working till he copy to all machines?
                        The batch below updates the inputfile 'computers.txt' after every run, only the names of computers that were not completed succesfully remain on that list. The names of computers that were succefully completed are added to a new list.
                        When the inputfile is gone that indicates the job is done.

                        Code:
                        @echo off & Setlocal
                        title,File Copy to a list of computers &color 9e
                        
                        (Set InputFile=computers.txt)
                        (Set DoneFile=Computers completed successfully.txt)
                        
                        If NOT exist "%InputFile%" goto :end
                        
                        (Set WorkFile=WorkFile%random%.txt)
                        >"%WorkFile%" (echo\;*** %date%-%time% *** & echo\)
                        Set n=0
                        
                        for /f "usebackq" %%a in ("%InputFile%") do (
                           echo pinging %%a
                           Set /a n+=1
                           >nul (ping -n 1 -w 750 %%a | find /i "TTL=") &&(
                             >nul 2>&1 (copy "C:\z\*" "\\%%a\C$\") &&(
                                echo -done-
                                >>"%DoneFile%" echo %%a ; %date%-%time%
                             ) ||(>>"%WorkFile%" (
                                  echo %%a ; Copy ERROR))
                           ) ||(>>"%WorkFile%" (
                                echo %%a ; offline))
                           echo\---------------------------------------)
                        
                        If %n% GTR 0 (
                           MOVE /Y "%WorkFile%" "%InputFile%"
                           ) ELSE (
                           Del "%WorkFile%" & Del "%InputFile%"
                           goto :end)
                        goto :eof
                        
                        :end
                        echo Mission accomplished!
                        >nul ping locahost -n 7
                        \Rems
                        Last edited by Rems; 6th January 2010, 23:53.

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment

                        Working...
                        X