Thursday, February 20, 2014

Notes on Windows Batch Scripting

Find a jar file given the class name?
http://stackoverflow.com/questions/1500141/find-a-jar-file-given-the-class-name
for %i in (*.jar) do @"C:\Program Files\Java\jdk1.6.0_24\bin\jar" tvf %i | find "JspServlet.class"&& echo %i 


Get-ChildItem -recurse -Filter *.jar | Foreach { jar tvf $_.fullname | Select-String -pattern "JspServlet.class"}

Get parent folder
http://stackoverflow.com/questions/16623780/how-to-get-windows-batchs-parent-folder
for %%i in ("%~dp0..") do set "folder=%%~fi"

Get current folder name
http://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command

for %%* in (.) do set CurrDirName=%%~n*


http://superuser.com/questions/160702/get-current-folder-name-by-a-dos-command
%0     - as the name how this batchfile was called
%~d0   - as the drive letter where this batchfile is located ('\\' in case of share)
%~p0   - as path (without the drive letter) where this batchfile is located
%~n0   - as filename (without suffix) of this batchfile
%~x0   - as filename's suffix (without filename) of this batchfile
%~a0   - as this batchfile's file attributes
%~t0   - as this batchfile's date+time
%~z0   - as this batchfile's filesize
%~dpnx - as this batchfile's fully qualified path+filename

Search classes in jar file
http://www.windows-commandline.com/search-classes-in-jar-file/
forfiles /S /M *.jar /C "cmd /c jar -tvf @file | findstr /C:"classname" && echo @path"
List the classes in a jar file
jar -tvf jarfile | findstr /C:".class"
Find all the jar files in a folder
dir /S /b *.jar

Echo date and time
echo %DATE% %TIME%
http://snipplr.com/view/21573/
set DATESTAMP=%DATE:~10,4%_%DATE:~4,2%_%DATE:~7,2%
set TIMESTAMP=%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2%

set DATEANDTIME=%DATESTAMP%_%TIMESTAMP%

*See what process is using a TCP port*
http://www.techrepublic.com/blog/the-enterprise-cloud/see-what-process-is-using-a-tcp-port-in-windows-server-2008/
netstat -a -n -o
netstat -ano | findstr 9999
tasklist  /svc /fi "PID eq 755784"
http://ss64.com/nt/tasklist.html
/fi FilterName [/fi FilterName2 [ ... ]]
/svc List information for each process without truncation.
TASKLIST /FI "imagename eq svchost.exe" /svc
TASKLIST /v /fi "STATUS eq running"

TASKLIST /v /fi "username eq SERVICE_ACCT05"

No comments:

Post a Comment