Loading ...
Sorry, an error occurred while loading the content.

Logic problems

Expand Messages
  • Andrew Streule
    My clever dynamic wake-on-lan script almost works but there seems to be some weird syntax/logic error that makes no error but clearly isn t working like its
    Message 1 of 22 , Mar 10, 2011
    • 0 Attachment
      My clever dynamic wake-on-lan script almost works but there seems to be
      some weird syntax/logic error that makes no error but clearly isn't
      working like its supposed to. The set commands don't work but the
      variables %%b and %%c definitely contain the correct information.
      =================================
      @echo off

      del temp.txt
      set mac=
      set ip=

      dsquery computer -limit 5000 dc=domain,dc=domain,dc=domain,dc=uk | find
      "%1" /I >> temp.txt

      for /f "tokens=2 delims==," %%a in ('type temp.txt') do (



      if exist \\server\share\lapmacs\%%a.log for /f "tokens=* delims= " %%b
      in ('type \\server\share\lapmacs\%%a.log') do set mac=%%b && echo %%b
      if exist \\server\share\ips\%%a.txt for /f "tokens=14 delims=: " %%c in
      ('type \\server\share\ips\%%a.txt') do set ip=%%c && echo %%c

      echo ..........%%a %mac% %ip%

      rem wolcmd %MAC% %IP% 255.255.0.0 7
      )

      ================================
      NOTES
      %1 contains a common computer name prefix
      The content of lapmaps\%%a.log is just a mac address
      The content of ips\%%a.txt is " IP Address. . . . . . . . . . . .
      : 192.168.20.23"




      Probably doing something simple wrong but don't know & trial/error not
      working.

      Thanks

      Andy
    • foxidrive
      ... This illustrates the issue - variables set in parentheses are not available for use within the parentheses. Unless you use delayed expansion. @echo off (
      Message 2 of 22 , Mar 10, 2011
      • 0 Attachment
        On 11/03/2011 01:07, Andrew Streule wrote:
        > My clever dynamic wake-on-lan script almost works but there seems to be
        > some weird syntax/logic error that makes no error but clearly isn't
        > working like its supposed to. The set commands don't work but the
        > variables %%b and %%c definitely contain the correct information.
        > =================================
        > @echo off
        >
        > del temp.txt
        > set mac=
        > set ip=
        >
        > dsquery computer -limit 5000 dc=domain,dc=domain,dc=domain,dc=uk | find
        > "%1" /I>> temp.txt
        >
        > for /f "tokens=2 delims==," %%a in ('type temp.txt') do (
        >
        >
        >
        > if exist \\server\share\lapmacs\%%a.log for /f "tokens=* delims= " %%b
        > in ('type \\server\share\lapmacs\%%a.log') do set mac=%%b&& echo %%b
        > if exist \\server\share\ips\%%a.txt for /f "tokens=14 delims=: " %%c in
        > ('type \\server\share\ips\%%a.txt') do set ip=%%c&& echo %%c
        >
        > echo ..........%%a %mac% %ip%
        >
        > rem wolcmd %MAC% %IP% 255.255.0.0 7
        > )
        >
        > ================================
        > NOTES
        > %1 contains a common computer name prefix
        > The content of lapmaps\%%a.log is just a mac address
        > The content of ips\%%a.txt is " IP Address. . . . . . . . . . . .
        > : 192.168.20.23"
        >
        >
        >
        >
        > Probably doing something simple wrong but don't know& trial/error not
        > working.
        >
        > Thanks
        >
        > Andy

        This illustrates the issue - variables set in parentheses are not
        available for use within the parentheses. Unless you use delayed expansion.


        @echo off
        (
        set a=abc
        echo try 1 %a%
        )
        echo try 2 %a%
        pause
      • Glenn B. Lawler
        ... If you type: SET /? You will get a full explanation about this. The short version is you need to enable delayed environment variable expansion and use the
        Message 3 of 22 , Mar 10, 2011
        • 0 Attachment
          On 11/03/2011 01:07, Andrew Streule wrote:
          > My clever dynamic wake-on-lan script almost works but there seems to
          > be some weird syntax/logic error that makes no error but clearly isn't
          > working like its supposed to. The set commands don't work but the
          > variables %%b and %%c definitely contain the correct information.
          > =================================
          > @echo off
          >
          > del temp.txt
          > set mac=
          > set ip=
          >
          > dsquery computer -limit 5000 dc=domain,dc=domain,dc=domain,dc=uk |
          > find "%1" /I>> temp.txt
          >
          > for /f "tokens=2 delims==," %%a in ('type temp.txt') do (
          >
          >
          >
          > if exist \\server\share\lapmacs\%%a.log for /f "tokens=* delims= " %%b
          > in ('type \\server\share\lapmacs\%%a.log') do set mac=%%b&& echo %%b
          > if exist \\server\share\ips\%%a.txt for /f "tokens=14 delims=: " %%c
          > in ('type \\server\share\ips\%%a.txt') do set ip=%%c&& echo %%c
          >
          > echo ..........%%a %mac% %ip%
          >
          > rem wolcmd %MAC% %IP% 255.255.0.0 7
          > )
          >
          > ================================
          > NOTES
          > %1 contains a common computer name prefix The content of
          > lapmaps\%%a.log is just a mac address
          > The content of ips\%%a.txt is " IP Address. . . . . . . . . . . .
          > : 192.168.20.23"
          >
          >
          >
          >
          > Probably doing something simple wrong but don't know& trial/error
          > not working.
          >
          > Thanks
          >
          > Andy

          If you type:
          SET /?

          You will get a full explanation about this. The short version is you need to
          enable delayed environment variable expansion and use the exclamation point
          (!) instead of the percent sign (%) to dereference the variables.

          Glenn Lawler
          www.incodesystems.com
        Your message has been successfully submitted and would be delivered to recipients shortly.