Solved

windows batch scripts

Posted on 2014-10-07
2
197 Views
Last Modified: 2014-11-06
someone who left the company has write the scripts below. I have some difficulties to understands what is the script doing. I'm now doing some search in internet as well.

If anyone here expert with batch  scripts, pls share with me how the scripts works.

@echo off

setlocal ENABLEDELAYEDEXPANSION

c:
cd\
cd /d X:\prog\Minyak\fp
set _localLogMinyak=logs\getValuesFP.cmd.log.txt
set _ltools=e:\pgrs\eaars\bin\tools
echo ------------------------------------------------------------------------------------->>%_localLogMinyak%


set _ldapClientTools=C:\Program Files\OpenLDAP\ClientTools
set _lderrorlog=logs\ldapsearchFP.log.txt
set _ldapSearchFileOperations=lookup\NoStaffFP.csv
set _ldapSearchFilter=NoStaff
set _outputFile=result\eddataFP.csv

del /Q /F %_outputFile% > nul 2>&1
%_ltools%\sleep2 12
echo %time% - Start quering the ports>>%_localLogMinyak%
set /a _failcount=0

for /l %%i in (1,1,50) do (
 X:\prog\Minyak\fp\portqry.exe -n ldap.tnb.com -e 389|C:\WINNT\system32\findstr.exe "TCP port"|C:\WINNT\system32\findstr.exe /c:": LISTENING"

 echo    return: !errorlevel!>>%_localLogMinyak%
 if not !errorlevel!==0 (
  set /a _failcount+=1
 ) else (
  echo failcount: !_failcount!>>%_localLogMinyak%
  goto port_listening
 )
 echo failcount: !_failcount!>>%_localLogMinyak%
 ping 1.1.1.1 -w 1000 -n 1>nul
)
goto _ldapattrib

:port_listening
echo port_listening>>%_localLogMinyak%

:_ldapattrib
::
:: ALL _ldapattrib HAVE A BLANK SPACE AFTER THE VALUE EXCEPT THE LAST ONE
::
set _ldapattrib=employeeType 
set _ldapattrib=%_ldapattrib%tnbBusinessRegionAcronym 
set _ldapattrib=%_ldapattrib%cn 
set _ldapattrib=%_ldapattrib%tnbBusinessGroupCode 
set _ldapattrib=%_ldapattrib%tnbOrganizationChartAcronym 
set _ldapattrib=%_ldapattrib%tnbCrossCompanyManagerID 
set _ldapattrib=%_ldapattrib%tnbTerminationDate 
set _ldapattrib=%_ldapattrib%tnbPayrollCountryCode 
set _ldapattrib=%_ldapattrib%tnbMRUCode 
set _ldapattrib=%_ldapattrib%ou 
set _ldapattrib=%_ldapattrib%tnbOrganizationChart 
set _ldapattrib=%_ldapattrib%tnbBusinessUnit 
set _ldapattrib=%_ldapattrib%tnbBusinessGroup 
set _ldapattrib=%_ldapattrib%mail 
set _ldapattrib=%_ldapattrib%co 
set _ldapattrib=%_ldapattrib%tnbCrossCompanyManager 
set _ldapattrib=%_ldapattrib%NoStaff 
set _ldapattrib=%_ldapattrib%tnbStatus 
set _ldapattrib=%_ldapattrib%tnbBusinessUnitAcronym 
set _ldapattrib=%_ldapattrib%tnbStartDate 
set _ldapattrib=%_ldapattrib%tnbBusinessRegion

echo %time% - Starting ldapsearch>>%_localLogMinyak%
"%_ldapClientTools%\ldapsearch.exe" -v -c -LLL -T "X:\prog\Minyak\fp" -x -h ldap.tnb.com -b ou=People,o=tnb.com -f %_ldapSearchFileOperations% (%_ldapSearchFilter%=%%s) %_ldapattrib%>eddataFP.tmp 2>%_lderrorlog%
rem "%_ldapClientTools%\ldapsearch.exe" -v -c -LLL -T "X:\prog\Minyak\fp" -D cn=tnbedeaars,ou=Applications,o=tnb.com -w PASSWORD -H ldaps://ldap.tnb.com -b ou=People,o=tnb.com -f %_ldapSearchFileOperations% (%_ldapSearchFilter%=%%s) %_ldapattrib%>eddataFP.tmp 2>%_lderrorlog%
echo %time% - Finished ldapsearch>>%_localLogMinyak%

echo %time% - Add dummy entry>>%_localLogMinyak%
type dummy_entry_FP.txt>>eddataFP.tmp
echo %time% - Finished adding dummy entry>>%_localLogMinyak%

%_ltools%\sleep2 2
echo.>>%_localLogMinyak%
echo %time% - Starting LDIFtoCSV>>%_localLogMinyak%
dir >>%_localLogMinyak%
LDIFtoCSV.exe -M 8 -F $ -o %_outputFile% -l logs\LDIFtoCSVFP.exe.log eddataFP.tmp
%_ltools%\sleep2 2
del /Q /F X:\prog\Minyak\fp\eddataFP.tmp
rem del /q /f X:\prog\Minyak\fp\lookup\NoStaffFP.csv
echo %time% - Finished LDIFtoCSV>>%_localLogMinyak%
echo.>>%_localLogMinyak%
dir >>%_localLogMinyak%
dir X:\prog\Minyak\fp\result >>%_localLogMinyak%

::


:: type %_lderrorlog%

:eof
echo %time% - END >>%_localLogMinyak%
exit

Open in new window

0
Comment
Question by:motioneye
2 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
Comment Utility
It would appear to be using Microsoft's Port Query utility to resolve an internal Thomas & Betts LDAP server, ldap.tnb.com, then determine if that server is listening on LDAP port 389 with the command:

 X:\prog\Minyak\fp\portqry.exe -n ldap.tnb.com -e 389|C:\WINNT\system32\findstr.exe "TCP port"|C:\WINNT\system32\findstr.exe /c:": LISTENING"

Open in new window


If this command does not result in an error, it will copy a text string to the logfile and perform an LDAP search using OpenLDAP's ldapsearch.exe in the People Organization Unit based on this criteria:

:: ALL _ldapattrib HAVE A BLANK SPACE AFTER THE VALUE EXCEPT THE LAST ONE
::
set _ldapattrib=employeeType 
set _ldapattrib=%_ldapattrib%tnbBusinessRegionAcronym 
set _ldapattrib=%_ldapattrib%cn 
set _ldapattrib=%_ldapattrib%tnbBusinessGroupCode 
set _ldapattrib=%_ldapattrib%tnbOrganizationChartAcronym 
set _ldapattrib=%_ldapattrib%tnbCrossCompanyManagerID 
set _ldapattrib=%_ldapattrib%tnbTerminationDate 
set _ldapattrib=%_ldapattrib%tnbPayrollCountryCode 
set _ldapattrib=%_ldapattrib%tnbMRUCode 
set _ldapattrib=%_ldapattrib%ou 
set _ldapattrib=%_ldapattrib%tnbOrganizationChart 
set _ldapattrib=%_ldapattrib%tnbBusinessUnit 
set _ldapattrib=%_ldapattrib%tnbBusinessGroup 
set _ldapattrib=%_ldapattrib%mail 
set _ldapattrib=%_ldapattrib%co 
set _ldapattrib=%_ldapattrib%tnbCrossCompanyManager 
set _ldapattrib=%_ldapattrib%NoStaff 
set _ldapattrib=%_ldapattrib%tnbStatus 
set _ldapattrib=%_ldapattrib%tnbBusinessUnitAcronym 
set _ldapattrib=%_ldapattrib%tnbStartDate 
set _ldapattrib=%_ldapattrib%tnbBusinessRegion

Open in new window


Overall, it appears the script ensures it can talk to the LDAP server, performs a targeted query against the LDAP server, and compares the results of that LDAP query to the contents and outputs the results to the directory X:\prog\Minyak\fp\result.

Do you need a line-by-line analysis of the scripts?
0
 

Author Comment

by:motioneye
Comment Utility
Hi WalkaboutTigger
If you could with line by line basis analysis, I really appreciate that, I knew some of the parts of the scripts but 2nd opinion I guess make me more confident
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now