Dumpcap (Wireshark) - Trying to capture files and store in subdirectories - batch-file

Does anyone have any idea on how to force dumpcap to create the directory before it writes in it? I am trying to capture packets for a year, and have a batch file that writes based on the year/month/day/hour, but unfortunately dumpcap doesn’t try and create the directory if it is not there.
Any suggestions?
dumpcap -i 2 -b duration:3600 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\capture -q
Any help would be appreciated.
(I know I could create all the directories ahead of time, or run it every hour with at/schtasks and create the directory beforehand. Looking for another way.)

Additionally, I found another workaround (This will store the files by hour and I just have a schtask that runs it each hour):
#echo off
For /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do (
SET HH24=%%a
SET MI=%%b
SET SS=%%c
SET FF=%%d
)
mkdir d:\pcaps\%year%
mkdir d:\pcaps\%year%\%month%
mkdir d:\pcaps\%year%\%month%\%day%
mkdir d:\pcaps\%year%\%month%\%day%\%HH24%
"c:\program files\wireshark"\dumpcap -i 2 -a duration:3600 -b filesize:100000 -P -w D:\pcaps\%year%\%month%\%day%\%HH24%\CORP.pcap -q

Does anyone have any idea on how to force dumpcap to create the directory before it writes in it?
No, because there is no way to do that; dumpcap never calls any routines that create a directory for the capture file. The only way to force it to do so would be to change it to do so and recompile it.

Related

Using FFMPEG to batch remove audio endings

I have over 1000 audio files, all of which end in a mouse click. I would like to remove the last half second from all of them. The audio files have different length (i.e. 15sec, 5 sec ...) But one thing in common with all of them is the last half second has a mouse click sound. How do I trim in bulk the ending of the mp3 files within a folder using windows 10 command line? I already have FFMPEG downloaded. Thank you!
This is two questions in one:
How to remove the last 0.5 seconds from inputs of arbitrary durations?
How to incorporate this into a Windows batch script?
I'll answer #1 because I'm not a Windows user. The batch scripting will be up to you.
Get duration using ffprobe:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp3
Trim using ffmpeg:
ffmpeg -i input.mp3 -t <duration> -c copy output.mp3
Replace <duration> with the output from ffprobe minus 0.5 seconds.
How to incorporate this into a Windows batch script?
This should do:
FOR %%A IN (*.mp3) DO (
FOR /F %%B IN ('ffprobe.exe -v error -show_entries format^=duration -of csv^=p^=0 "%%~A" ^| xidel -s - -e ". - 0.5"') DO (
ffmpeg.exe -i "%%~A" -t %%B -c copy "%%~dpnA_trimmed.mp3"
)
)
First of all, doing floating point calculations in Batch is officially impossible and unofficially really hard to script. That's why I suggest to let Xidel do the math. It's first of all a command line tool to download and extract data from HTML/XML/JSON, but it can do A LOT more!
Loop over all mp3-files in the current directory.
The ffprobe command as suggested by llogan piped to Xidel to subtract the 0.5s. For example, 25.547755 now becomes 25.047755.
Don't forget to escape the necessary characters inside the for-loop! The = and | in this case.
The ffmpeg command as suggested by llogan, which opens "%%~A (the mp3-file), sets the duration to %%B and creates a new mp3-file (<filename>_trimmed.mp3).
This code assumes the mp3-files, ffprobe.exe, xidel.exe and ffmpeg.exe are all in the same directory.

Audio Conversion: Nesting loops in batch file gives no output

I'm converting a couple thousand .wem files to .wav format. Since .wem is an obscure file format, I've decided to convert the files with SoX.
The SoX standard installation includes a batch file for use with mass converting raw files, which I've happily used. I've modified the example to remove the need to drag and drop files onto the batch file, using nested loops.
cd %~dp0
mkdir converted
for %%f in (*.wem) do FOR %%A IN (%*) DO sox -t raw -e signed-integer -b 16 -c 1 -r 44100 %%A "converted/%%~nA.wav"
pause
It creates a /converted directory just fine, and then proceeds to output the command, the directory, and then moves on to (supposedly) the next file. Unfortunately, opening the /converted directory reveals that nothing was generated at all, and the conversion took a lot less time than it should have. I've tested it with .wem files prior, and it converts just fine, so I don't think it has anything to do with the format. More likely, it just has something to do with my amateur batch file programming. Any ideas?
Solved, thanks to Mofi.
Finished code:
cd %~dp0
mkdir converted
for %%I in (*.wem) do sox -t raw -e signed-integer -b 16 -c 1 -r 44100 "%%I" "converted\%%~nI.wav"
pause
Seems I really could do it in one loop.

Sending sqlcmd output file to directory that is a variable

Currently, the following code in a batch file works: it runs all SQL scripts in %SCRIPTFOLDER% and sends each script's output to a CSV within the same folder as the scripts.
FOR /F "tokens=*" %%S IN (
'DIR /B "%SCRIPTFOLDER%\*.sql" '
) DO (
sqlcmd -b -S %INSTANCE% -d %DATABASE% -i "%%~fS" -s "|" -o "%%~dpnS.csv" -W
IF ERRORLEVEL 1 GOTO errorhandling
ECHO %%~nS.csv successfully created
)
What I'd like to do is allow the user to specify where the generated CSVs get sent to using a variable %OUTPUTFOLDER%.
I tried placing %OUTPUTFOLDER%, which is a full path, drive, and folders (e.g. D:\some folder\output) in various positions within %%~dpnS.csv. Specifically,
%%~dp%OUTPUTFOLDER%nS.csv
and
%%~dpn%OUTPUTFOLDER%S.csv
but they didn't work and I'm (probably obviously to you) woefully inept at batch file syntax!
I understand that dp is the drive and path and that S is the file name, but I'm not sure how to integrate that with a the variable that is the path.
The iterating variable is %%S, the modifier ~dpn forces an evaluation of drive path and name.
In this case you want to specify the drive and path yourself so depending on wether %OUTPUTFOLDER% has a trailing backslash
-o "%OUTPUTFOLDER%%%~nS"
or not use:
-o "%OUTPUTFOLDER%\%%~nS"

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

bat file for changing the timestamp of a file

I would like to have a bat file find a specific file within a directory and have it update the time stamp to be current and or synched with the time of activating the bat file.
You don't need to use "touch.exe" to accomplish this. A simple script like this will prove the case:
#echo off
ECHO Test1:
SET FILENAME=test.xml
copy /b %FILENAME% +,,
dir %FILENAME%
timeout 64
ECHO Test2:
copy /b %FILENAME%,,+
dir %FILENAME%
pause
This proves that there are 2 different ways to do this, syntactically.
Can you use touch (already suggested in Jubjub Bandersnatch's comment):
change the modification time from all TXT files to now:
touch -m *.txt
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
-a change only the access time
-c do not create any files
-d, --date=STRING parse STRING and use it instead of current time
-f (ignored)
-m change only the modification time
-r, --reference=FILE use this file's times instead of current time
-t STAMP use MMDDhhmm[[CC]YY][.ss] instead of current time
--time=WORD access -a, atime -a, mtime -m, modify -m, use -a
--help display this help and exit
--version output version information and exit
STAMP may be used without -t if none of -drt, nor --, are used.
I ended up using:
copy Certain.config,,+
TIMEOUT 2
net stop Certain_Services
TIMEOUT 1
net start Certain_Services
it will update the Modified Date, stop and restart the services.

Resources