Solved

windows batch scripts

Posted on 2014-10-07
2
204 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
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Command to modify Registry entry 5 134
Active DirectoryScript to change the Pager Field 1 93
Copy dir and files with robocopy 2 72
Windows 8.1 Enterprise Pauses Frequently 27 120
The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
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…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 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