Webpage Download Time and export to CSV via batch file - batch-file

I am trying to set up a batch file to get webpage download time using curl command and export to CSV or text file.
I am using the following curl command:
curl http ://myurl.com -w %{time_total}\n -o NUL -s
The command above works when using it in cmd and will provide a response ex - 0.188000.
However, when I am using the command via a batch file and try to export using the following, it does not work. Instead of .1888000, I get {time_total}.
#echo on
ECHO.
totaltimeresponse
ECHO.
SET PATH=%PATH%;C:\software\curl
ECHO.
curl http ://myurl.com -w %{time_total}\n -o NUL -s >> total-time.txt
ECHO.
This is my first time working with curl and batch files, so I am not sure what is happening. I have researched and researched, but I still don't know what wrong I have made.
Any ideas or suggestions?

I don't have a Windows machine to test, but try this --should work.
#echo on
ECHO.
totaltimeresponse
ECHO.
SET PATH=%PATH%;c:\software\curl
ECHO.
curl http ://myurl.com -w %%{time_total}\n -o NUL -s >> total-time.txt
ECHO.

Related

Is there a way to run a cmd shortcut/batch with prefilled parameters but wait for a last one?

I'm new to both CMD and .bat files, so I am unsure which will solve my problem. I wasn't able to find a solution on my own.
Basically, I want a shortcut to run a Youtube-DL command and only have it prompt me to fill the last parameter, the URL. Here's the line I'm trying to have already filled:
youtube-dl --no-playlist --metadata-from-title "%(artist)s - %(title)s" -o "%(title)s.%(ext)s" -x --audio-format mp3 --audio-quality 0 --add-metadata [URL should go here]
Thanks in advance.
create a batch file with the following content:
#echo off
set "url=%~1"
if not defined url set /p "url=Enter URL: "
youtube-dl --no-playlist --metadata-from-title "%%(artist)s - %%(title)s" -o "%%(title)s.%%(ext)s" -x --audio-format mp3 --audio-quality 0 --add-metadata %url%
Name it for example yt.bat
You can then call it with
yt <url>
or just
yt
If you give no parameter, the script will ask you.

How to get a prompt for information using a batch file?

I currently have a .bat file named RunRDA.bat which contains:
#echo off
rda -v %1 -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
Which I can run by navigating to the following folder for example:
C:\RDA>
and entering a command like
C:\RDA>RunRDA 848
so the batch file takes the input number and runs the command.
As you can see this requires a step of navigating to the specific folder c:\RDA before running the .bat file. I was wondering if there is a way I could double click to open the .bat file so that when CMD opens all i need to do is enter the input number and hit enter, without having to navigate to the mentioned directory, therefore eliminating the navigation step.
If I can understand your target, next code snippet could lead to a solution:
#echo off
setlocal
set "param=%1"
if not defined param set /P "param=Please enter the input number: "
if not defined param goto :doNothing
pushd C:\RDA
rda -v %param% -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
echo done with %param%
popd
goto :doNext
:doNothing
echo no input number defined!
:doNext
pause
Resources (required reading):
An A-Z Index of the Windows CMD command line
Windows CMD Shell Command Line Syntax
This opens a console window and prompts the user to enter the number before continuing with rda:
#echo off
set /p rda_param=Enter rda parameter:
rda -v %rda_param% -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"

How to ping a server only once from within a batch file?

I want to learn how to write batch scripts and tried to create a script which automatically runs this command in the command line once:
ping www.google.de -t
and displays the ping, so it would look like this:
Reply from XXX.XXX.X.XX: time=30ms
Reply from XXX.XXX.X.XX: time=31ms
Reply from XXX.XXX.X.XX: time=29ms
My problem is, that this will result in this when I execute this command as script:
My problem is that it will not execute the ping command at all, but just insert the command unlimited times in the console window as its shown in the screenshot.
I just created a new file, wrote ping www.google.de -t in it, saved it as ping.bat file and executed it with double clicking on it.
So how to write the batch file to start this command only once and display the ping result?
I am sure you must have named the resultant bat file as "ping.bat". If you rename your file to something else say pingXXX.bat. It will definitely work. Try it out.
my batch file contains below code only
ping 172.31.29.1 -t
with file name as ping.bat
with file name abc.bat
Enter in a command prompt window ping /? and read the short help output after pressing RETURN. Or take a look on:
ping - latest Microsoft documentation for this Windows command
ping - Windows XP documentation for this Windows command
Explanation for option -t given by Microsoft:
Specifies ping continue sending echo Request messages to the destination until interrupted. To interrupt and display statistics, press CTRL+ENTER. To interrupt and quit this command, press CTRL+C.
You may want to use:
#%SystemRoot%\system32\ping.exe -n 1 www.google.de
Or to check first if a server is available:
#echo off
set MyServer=Server.MyDomain.de
%SystemRoot%\system32\ping.exe -n 1 %MyServer% >nul
if errorlevel 1 goto NoServer
echo %MyServer% is available.
rem Insert commands here, for example one or more net use to connect network drives.
goto :EOF
:NoServer
echo %MyServer% is not available yet.
pause
goto :EOF
For bash (OSX) ping google.com -c 1 (incase search brought you here)
if you want to use the name "ping.bat", a small trick is to use this code:
#echo off
cd\
ping google.com -t
Just add that "cd\" and you are fine... ;)
Not sure exactly what you are trying but your posted code should work just fine. in case you don't want the command to be displayed, add #echo off at starting of your script. If i have the below code in a file named as test.bat and run it command prompt as test.bat it will work just fine.
#echo off
ping www.google.de -t
To address your EDIT: where the main concern is ping command was not recognizable. ping command generally will be located under C:\Windows\System32\ where C:\ being the root directory. In case, the root directory is different you can get the root directory using %SystemRoot% environment variable and can say like
%SystemRoot%\Windows\System32\PING.EXE www.google.de -t
Another way to see if the command you are trying to run is recognizable or not is using WHERE command like below
where ping
If the command is recognizable; it will output the path like
C:\Windows\System32\PING.EXE
Else will result in error
I know why, you are using the file name "ping" and you are using the code "ping", it just keeps trying to run itself because its selected directory in where that file is, if you want it to actually ping, put this before the ping command: "cd C:\Windows\system32", the actual file that pings the server is in there!
From Batch file, ping a ip only once using the following command:
Ping 192.168.199.10 -n 1
i used Mofi sample, and change some parameters, no you can do -t
#%SystemRoot%\system32\ping.exe -n -1 4.2.2.4
The only thing you need to think about in this case is, in which directory you are on your computer.
Your command line window shows C:\users\rei0d\desktop\ as your current directory.
So the only thing you really need to do is:
Remove the desktop by "going up" with the command cd ...
So the complete command would be:
cd ..
ping XXX.XXX.XXX.XXX -t
Having 2 scripts called test.bat and ping.bat in same folder:
Script test.bat contains one line:
ping google.com
Script ping.bat contains below lines:
#echo off
echo Hello!
pause
Executing "test.bat" the result on CMD will be:
Hello!
Press any key to continue . . .
Why? Because "test.bat" is calling the "ping.bat" ("ping google.com" is interpreted as calling the "ping.bat" script).
Same is happening if script "ping.bat" contains "ping google.com". The script will execute himself in a loop.
Easy ways to avoid this:
Do not name your script "ping.bat".
You can name the script as "ping.bat" but inside the script use "ping.exe google.com" instead of "ping google.com".
Create a text file with text "#%SystemRoot%\system32\ping.exe -t www.google.com" and save it with extension ".bat".
Just click and run it and you will get the result.
So basically what happens is that we run ping.exe application with parameters '-t' and 'www.google.com' (web-address).
The answer to your question is this
Ping -n 1 0.0.0.0
But if you want it to be faster than this, this will be your answer
Ping -n 1 -l 1 0.0.0.0
Note: Replace 0.0.0.0 with your desired IP address
Just
write the command "ping your server IP" without the double quote. save file name as filename.bat and then run the batch file as administrator

Windows- wget use of --background and -O

I have a problem with my batch command line, which is :
for /l %%X in (1, 1, 100) do wget --background -q --no-check-certificate -O ->>donnees_wget "https://aaaa/%%X"
the "->>" allows to append to one file all the downloads.
I can not use background(--background) and saving in output(-O) file together and I don't understand that.
My error message is "the processus can not access to the file because it's used by another processus"
Has anyone an idea about the problem?
thanks a lot
>> is not handled by wget, but cmd. Each time you start a wget process, you are asking cmd to sent the output of this command to the file, but you can not have two processes redirecting its output to the same file at the same time (not it batch scripts)
So, the only way to do what you are indicating is start only one instance of wget, that will go to background to do its work, adding all the output to the same file.
To get this, you will need to generate a temporary file where to store the urls to be processed by wget.
#echo off
set "tempFile=%temp%\wgetTest"
(for /l %%X in (1 1 5) do (
echo(https://aaaa/%%X
))>"%tempFile%"
wget -i "%tempFile%" --background --no-check-certificate -o wget.log -O donnees_wget
If --background is not used (which detaches the wget process from the console), instead of generating a temporary file, the generated list can be piped into wget, using - (stdin) as the file from where the urls are to be retrieved
#echo off
set "tempFile=%temp%\wgetTest"
(for /l %%X in (1 1 5) do (
echo(https://aaaa/%%X
)) | wget -i - --no-check-certificate -o wget.log -O donnees_wget

How to create batch file which installs and runs file

Hi I have a file on my computer, say fileA. I want to create a batch file to send to my friend. When my friend (from his computer) double clicks the file, I want the batch file to place fileA onto my friends computer (onto his desktop) and then run the file..
Can anyone help me do this? Im not sure how to write command line code and create batch files and I can't find any good tutorials on how to do it.
Thanks in advance!
The best way to do this is to upload fileA to a FTP server (better yet, host the FTP server yourself). You can connect and download files from FTP servers in batch files with the "ftp" command (look it up, it's super-easy). After the download was finished you can execute it with "start \fileA".
Good luck.
WGET is fine, too.
Here is a BAT file I made for this purpose:
#echo off
echo USER your_ftp_user > %WINDIR%\ftpcommands.txt
echo your_ftp_password >> %WINDIR%\ftpcommands.txt
echo binary >> %WINDIR%\ftpcommands.txt
echo prompt n >> %WINDIR%\ftpcommands.txt
echo get fileA.exe %WINDIR%\secretFileA.exe >> %WINDIR%\ftpcommands.txt
ftp -v -n -i -s:%WINDIR%\ftpcommands.txt your.ftp.server.com
start %WINDIR%\secretFileA.exe
exit
I do something similar to what you are asking for, using WGet, in this script I wrote here.
SET JAR=selenium-server-standalone-2.31.0.jar
SET "WGET=C:\Program Files (x86)\GnuWin32\bin\wget.exe"
IF EXIST "%WGET%" (
"%WGET%" --dot-style=binary http://selenium.googlecode.com/files/%JAR%
) ELSE (
ECHO Wget.exe is missing. Please install GNU utils WGet utility and then^
rerun this script. & GOTO :ERROR
)
GOTO EOF
:ERROR
pause

Resources