?
Solved

windows batch scripts

Posted on 2014-10-07
2
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 2000 total points
ID: 40366538
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
ID: 40367474
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

718 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