Do a whois by reading a the domains from a text file - text

I am trying to do a WHOIS for around 50 domains, i have searched on here and found a script that looks like it works but when i run it, it says:
"The Maximum setlocal recursion has been reached"
"The Process can not access the file, it is being used by another process"
Here is the code.
#echo off
setlocal
for /F "tokens=* EOL=# delims=" %%D in (e:\domains.txt) do call :reportit "%%~D"
endlocal
goto :eof
:reportit
setlocal
set "domain=%~1"
echo " Retrieving details for: %domain%"
echo " WHOIS: %domain%" >> e:\results.txt
echo "=============================================================" >> e:\results.txt
whois %domain% >> e:\results.txt
timeout 8
endlocal
exit /b
Any help will be much appreciated

Don't use WHOIS as the name of your batch.

Related

Cannot set environmental variable inside a loop in a batch script

I have a batch script that works great and it does the following:
download EDI files from sftp server
generate a dynamic ftp scripts based on the filenames that were downloaded
uploads the file to an internal ftp server via FTP script
I need to modify the batch file to look at the content as some data coming in maybe missing a 0. I do have the logic on how to do this, however, I cannot add the logic to the loop I have as variables do not work.
Below is loop where I want to add the part to correct missing leading zero (that would be in position 4):
for /F "tokens=*" %%A in (c:\scripts\permitsin.txt) do (
echo put %%A /qsys.lib/MAEPFTDTA.lib/PERMITIN.file/%%A >> c:\scripts\ftp-to-scoopsoft.ftp1
)
What I need to do is add an environment variable which will be the content of the file and below is the sample code:
set /p string =< %%A
echo Value for string is set to %string%
echo %string:~9,1% | find "ECHO is on." > nul
if not errorlevel 1 goto Found0
echo no space found
goto End
:Found0
echo found space
echo below is what the correct number needs to be
echo %string:~0,3%0%string:~3% > %%A
:End
I need this to work in batch file as security requirements does not allow PowerShell on the servers.
for /F "tokens=*" %%A in (c:\scripts\permitsin.txt) do (
for /F "delims=" %%S in (%%A) do (
setlocal enabledelayedexpansion
set "string=%%S"
if "!string:~9,1!"==" " echo !string:~0,3!0!string:~3!> %%A
endlocal
)
echo put %%A /qsys.lib/MAEPFTDTA.lib/PERMITIN.file/%%A >> c:\scripts\ftp-to-scoopsoft.ftp1
)
should do what you appear to need. Test on sample data first, of course.
Here's the how : Stephan's DELAYEDEXPANSION link
And it saves a lot of work if you tell us what you want to do rather than how you want to do it.

joining lines while adding white-spaces to select strings in CMD is not working

my test string is:
this is a sentence.
google.com
here is another sentence.
microsoft.com
this sentence has no period
my code is:
#echo off
setlocal EnableDelayedExpansion
set row=
#((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%find.exe" "."^<"%UserProfile%\i.txt"^"')Do #Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"
echo %row% >%userprofile%\o.txt
echo %row%
C:\Users\qwerp>joint3
ECHO is off.
i was expecting to get:
google.com microsoft.com
instead i got:
ECHO is off.
what am i doing wrong?
Given your example file content change and the stated intention, this may be sufficient for your needs, simply changing find.exe to findstr.exe, (with appropriate options):
#((For /F "EOL=|Delims=" %%# In ('^""%__AppDir__%findstr.exe" "\." "%UserProfile%\i.txt"^|"%__AppDir__%findstr.exe" "[^\.]$"^"')Do #Set /P "=%%# "<NUL)&Echo()>"%UserProfile%\o.txt"

Remove Brackets from Variable (CLI-Windows)

Based on the code below, the output of Var is (COM19). I was wandering what command can be used to remove the brackets? Tried using sed, but would ideally want a solution that doesn't not require additional installations on Windows.
#echo off
setlocal
wmic path win32_pnpentity get caption /format:list > output.txt
for /f "tokens=4" %%a in ('find /i "USB Serial Port" output.txt') do set var=%%a
pause
goto :EOF
for /f "delims=()" %%a in ("%output%") do (echo %%a)
Managed to solve the issue ussing the delims, in line with the token function. Code can be seen below.
#echo off
setlocal
wmic path win32_pnpentity get caption /format:list > output.txt
for /f "tokens=2 delims=()" %%a in ('find /i "USB Serial Port" output.txt') do set var=%%a
pause

How do i capture a variable from a text file with a batch script?

Hi I'm trying to write a batch script that reads a long text file, finds a line that says:
Location: xxxxxxxx
And saves xxxxxxxx (only) as a variable that i can use later in the script.
xxxxxxxx is an ID and there is nothing else on that line.
Can someone help?
This works, too.
for /f "tokens=2" %a in ('type longtextfile.txt ^|findstr /b "Location"') do set location=%a
echo %location%
EDIT: Adding Aacini's more efficient way of doing this:
for /f "tokens=2" %a in ('findstr /b "Location" longtextfile.txt') do set location=%a
echo %location%
There are just a few standard Windows commands required for this simple task:
#echo off
set "TextFile=C:\Temp\Text file to search for location.txt"
if not exist "%TextFile%" echo Can't find file: "%TextFile%"& goto :EOF
for /F "usebackq tokens=1* delims=: " %%I in ("%TextFile%") do (
if /I "%%I" == "Location" (
set "Location=%%J"
goto FoundLocation
)
)
echo No location found in file: "%TextFile%"
goto :EOF
:FoundLocation
echo Location is: %Location%
On second line the name of the text file with path must be defined.
To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.
echo /?
for /?
if /?
goto /?
set /?

Search specified directory and output location of item(s) if found

Like the title says, I would like to know how to search a specified directory for a specified file using a for loop in a windows batch script. I can't use any 3rd party software.
Heres what I have at the moment:
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
%loc% is the location in which it should search.
%searchterm% is the file (e.g "hello.txt") that the script much search for.
It must output any files found (including their full path) on the screen and into the wefound.txt.
Let me know if you need more detail.
for /f "delims=" %%f in ('dir /s /b /a-d "%loc%\%searchterm%"') do (
echo %%f
echo %%f>> "%genloc%wefound.txt"
)
To get the for /r command recursively enumerate the files under a starting point, the file set must include some wildcard character (* or ?). As you know the exact filename, let the dir command do the work of searching the file.
for /R "%loc%" %%f in ("%searchterm%") do (
echo %%~Ff
echo %%~Ff>> "%genloc%wefound.txt"
)
For further details, type: FOR /?
Why complicate things with FOR? All you need is the DIR command:
dir /s /b /a-d "%loc%\%searchterm%>"%genloc%wefound.txt"&type "%genloc%wefound.txt"
The solution is even better if you can get your hands on a Windows port of the tee command (there are numerous free versions available). You could use my hybrid JScript/batch implementation of tee
dir /s /b /a-d "%loc%\%searchterm%"|tee "%genloc%wefound.txt"

Resources