| 1. |
Solve : Need Help Debugging DOS Script? |
|
Answer» I have the batch file below. Basically, if I login the batch file should do nothing, and if Insert backslashes where needed But, will this work? It seems to be complicated command line. However, yours is clear and pretty. Echo Off ::Detect an anomalous logon. If none detected file takes no action. If %Username% neq Tom ( ::Get the time and date FOR /F "tokens=5 delims=. " %%a IN ('ECHO ^| TIME ^| FIND "current"') do set Trun=%%a FOR /F "tokens=6" %%a IN ('ECHO ^| DATE ^| FIND "current"') do set Drun=%%a ::Build the log file--if necessary--then log the data if not exist "C:\Output\Logons.txt" ( echo Date Time User Name >> "C:\Output\Logons.txt" echo ---- ---- --------- >> "C:\Output\Logons.txt" ) ::Write the date, time, and user name to the output file. echo %Drun% %Trun% %username% >> "C:\Output\Logons.txt" ::Create the Anomalous Logon notification message. echo Anomalous logon detected. Check C:\Output\Logons.txt for more information. >> "C:\Documents and Settings\Tom\Start Menu\Programs\Startup\AnomalousLogons.txt" )vishuvishal, We do not need a for loop to record and save %DATE% and %TIME% in a log file. But I will test the for loop code and post back the results. The editor here or with the Proxy Server is not working for me correctly. I might need to take a picture of the code while on my machine. It is pretty but we cannot copy and paste from the picture. What happened when you tested the for loop code? Post your results.He he didn't work Actually I was trying to figure out the procedure happened on this code. But found myself dumb. So, I think I am just beginner. However, your code are awesome so simple. Quote from: vishuvishal on August 09, 2010, 02:49:44 PM
Yes, the For loop by the Original Poster worked. Quote from: vishuvishal on August 09, 2010, 04:46:43 PM
The following code was mangled by my Poxy Editor. Look at the above SCREEN shot for a clear picture of the code. C:\\\\test>type vis89.bat Echo Off set USERNAME=%1 echo USERNAME=%USERNAME% SETLOCAL EnableDelayedExpansion echo. > C:\\\\test\\\\Logons.log If \\\"%USERNAME%\\\" EQU \\\"Tom\\\" goto :end FOR /F \\\"tokens=5 delims=. \\\" %%a IN (\\\'ECHO ^| TIME ^| FIND \\\"current\\\"\\\') do ( set Trun=%%a ) FOR /F \\\"tokens=6\\\" %%a IN (\\\'ECHO ^| DATE ^| FIND \\\"current\\\"\\\') do set Drun=%%a echo Date Time User Name >> C:\\\\test\\\\Logons.log echo ---- ---- --------- >> C:\\\\test\\\\Logons.log echo !Drun! !Trun! !USERNAME! >> C:\\\\test\\\\Logons.log echo Anomalous logon detected. >> C:\\\\test\\\\Logons.log goto :secondend :end echo %1 was the only User exit /b :secondend echo %1 was a Bogus User >> C:\\\\test\\\\Logons.log echo Type logons.log Type logons.log Output: C:\\\\test> vis89.bat Tom USERNAME=Tom Tom was the only User C:\\\\test> vis89.bat vis USERNAME=vis Type logons.log Date Time User Name ---- ---- --------- 08/09/2010 18:23:30 vis Anomalous logon detected. vis was a Bogus User C:\\\\test> I should say your bat is worth than this. Cause ur's simple and good. Thanks and regards VishuVis, The for loop is not necessary. |
|