Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

windows batch scripts

Posted on 2014-10-07
2
Medium Priority
?
220 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 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

916 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