Issues with batch write to txt - date

I am working on a fancy Zip archive cracker and its working perfectly.
And I successfully made it write the output to a log file. however my problem is:
if I run a crack on the same file again just couple of seconds later, it will overwrite the already existing log, but what I want to do is:
if the log file already exist. it will not overwrite the log file. but it will ADD in the new output of the new crack to the already existing file so when I open the log I will then see both of the cracks that I have done in same log file.
heres the code:
(
echo ==============================================
echo Crack log
echo ==============================================
echo.
echo PASSWORD FOUND!
echo Date/time log for decryption: %Date%\%time%
echo FILE = %NAME%
echo CRACKED PASSWORD = %PSWD%
echo Tests: %PSWD1%
echo.
echo Time Spendt to crack Archive: %hh%:%mm%:%ss%,%cc%
echo Hours: %hh%
echo Minutes: %mm%
echo Seconds: %ss%
echo Centisecods: %cc%
) > %Date%_Cracklog_%NAME%.txt
if exist %Date%_Cracklog_%NAME%.txt >> %Date%_Cracklog_%NAME%.txt
ok this problem has now been solved by:
#Aacini and #mofi
Solution: Change ) > %Date%Cracklog%NAME%.txt by ) >> %Date%Cracklog%NAME%.txt and delete the next line
==========================================================================
however now I got another problem.
i managed to add in on bottom line a function that creates a directory for each crack log. wich looks like this:
"MKDIR Logs\%name%
) >> %Date%Cracklog%NAME%.txt"
the mkdir works perfectly. the point with it is creating a subdirectory under the logs folder with the name of the cracked zip archive.
and the problem that is still there is that I got no idea how to make the script to create the actual log file inside that directory,
ive been googling and testing several things but I find nothing that really works. and at the same time. if I decide to crack another file, well yeh then the scripts makes a new sub directory but then I also want the new log file into its belonging folder.
anyone got any idea how to fix that?
(thanks for all help so far<3 I love ya guys)
if you choose to help me futher. please write an example or a helping answere by clicking the answere question button so i can give you reputation :D)
==============================================================================
Edit:
Managed to find out the last problem myself, I just took a break from all thinking then went back with a cup of coffee and then voila solution popped up in my head... I guess I was just a bit tired. however this is how I solved the problem:
(
echo ==============================================
echo Crack log
echo ==============================================
echo.
echo PASSWORD FOUND!
echo Date/time log for decryption: %Date%\%time%
echo FILE = %NAME%
echo CRACKED PASSWORD = %PSWD%
echo Tests: %PSWD1%
echo.
echo Time Spendt to crack Archive: %hh%:%mm%:%ss%,%cc%
echo Hours: %hh%
echo Minutes: %mm%
echo Seconds: %ss%
echo Centisecods: %cc%
MKDIR Logs\%name%
) >> Logs\%name%\%Date%_Cracklog_%NAME%.txt

Related

PHP script works from browser but not from Windows Server Task Scheduler or from CMD/PS

I have this simple script called webcam.php to acquire some screenshot from webcams
<?php
$d=date('YmdHis');
$url = 'http://xxx:40801/snap.jpeg?'.$d;
$img = 'camera_east.jpg';
echo file_put_contents($img, file_get_contents($url));
$url = 'http://xxx:40802/snap.jpeg?'.$d;
$img = 'camera_west.jpg';
echo file_put_contents($img, file_get_contents($url));
echo $d;
?>
and if I call http://xxx/webcam.php from browser, everything's OK:
I find the two pictures in the folder, and the script returns the length of the files and the timestamp as echoes.
I tried to make this script to be executed by the windows scheduler, but although it returns 0x0 the pictures are not updated.
(I tried also unlinking the images, and also using curl but nothing changes)
Then I tried to run the PHP script from command line (also from PowerShell):
something like:
C:\Program Files\PHP\v7.2\php.exe -f C:\\webcam.php
but again, although it seems working, since it returns the length of the two files and the timestamp, the pictures are not updated and if I add unlink command, files are not cancelled:
Clearly folder has all permissions...
I've not big experience in PHP... :-(
what can be wrong?
Thanks!
obviously from cmd/ps/scheduler requires the full path,
while from browser can accept relative path

Bat file Works On my pc when copied to another pc. Syntax error

First time making a bat file.
I complied this code and on my pc it make a folder with the date stamp in a backup folder.
Works great on my pc but when i transfer it to another computer I get Syntax error. And no folder get created.
I think it has to do with the mkdir c:\backup\%DATE%
Please see the code below
#echo off
cls
echo Date format = %DATE%
echo dd = %date:~0,2%
echo mm = %date:~3,2%
echo yyyy = %date:~6,4%
echo.
mkdir c:\backup\%DATE%
Please all any help would be greatly appreciated.
Regard Kenneth
Your date format has slashes in it, which are not allowed in directory names. On my system, for instance, echo %DATE% produces 03/02/2016, which is not a legal directory name on Windows.
Use something like this instead:
SET Today=%Date:~6,4%%Date:~0,2%%Date:~3,2%
echo %Today%
The above produces 20160302 with my time format settings.
You can then use mkdir c:\backup\%Today%, which will create the c:\backup\20160302 folder if run now with my date format settings.
Adjust the values around the ~ as needed to match the date format on your system.

Windows (All) how to append date to end of new folder creation?

I'm trying to figure out how to create a new folder that has the date, not time, appended to the end of the directory name. I just need the current time of creation, and nothing more.
Trying to use something really basic like the following as an example...
if exists CNC_%date% goto EXIST
if not exists CNC_%date% goto CREATE
:CREATE
mkdir CNC_%date%
:EXIST
echo Folder already exists!
echo Check directory and rename it to prevent loss of data.
echo.
echo Press any key to exit.
pause >nul
goto END
:CREATE
echo Creation successful!
echo Press any key to exit.
pause >nul
:END
exit
... results in the creation of a nested directory like "C:\"CNC_Fri 11"\22\2013" because of the backslashes.
IS there any way to pipe the backslashes through a native Windows program, and switch them with underscores? In Linux grep would have been my answer, but I need a native Windows method as this needs to be portable.
mkdir cnc_%date:/=_%
Use the date variable with the slashs replaced with underscore

Script response if md5sum returns FAILED

Say I had a script that checked honeypot locations using md5sum.
#!/bin/bash
#cryptocheck.sh
#Designed to check md5 CRC's of honeypot files located throughout the filesystem.
#Must develop file with specific hashes and create crypto.chk using following command:
#/opt/bin/md5sum * > crypto.chk
#After creating file, copy honeypot folder out to specific folders
locations=("/share/ConfData" "/share/ConfData/Archive" "/share/ConfData/Application"
"/share/ConfData/Graphics")
for i in "${locations[#]}"
do
cd "$i/aaaCryptoAudit"
/opt/bin/md5sum -c /share/homes/admin/crypto.chk
done
And the output looked like this:
http://pastebin.com/b4AU4s6k
Where would you start to try and recognize the output and perhaps trigger some sort of response by the system if there is a 'FAILED'?
I've worked a bit with PERL trying to parse log files before but my attempts typically failed miserably for one reason or another.
This may not be the proper way to go about this, but I'd want to be putting this script into a cronjob that would run every minute. I had some guys telling me that an inotify job or script (I'm not familiar with this) would be better than doing it this way.
Any suggestions?
--- edit
I made another script to call the script above and send the output to a file. The new script then runs a grep -q on 'FAILED' and if it picks anything up, it sounds the alarm (tbd what the alarm will be).
#!/bin/bash
#cryptocheckinit.sh
#
#rm /share/homes/admin/cryptoalert.warn
/share/homes/admin/cryptocheck.sh > /share/homes/admin/cryptoalert.warn
grep -q "FAILED" /share/homes/admin/cryptoalert.warn && echo "LIGHT THE SIGNAL FIRES"
Use:
if ! /opt/bin/md5sum -c /share/homes/admin/crypto.chk
then
# Do something
fi
Or pipe the output of the loop:
for i in "${locations[#]}"
do
cd "$i/aaaCryptoAudit"
/opt/bin/md5sum -c /share/homes/admin/crypto.chk
done | grep -q FAILED && echo "LIGHT THE SIGNAL FIRES"

Send the result of multiple commands to one text file?

This is what I have so far - my dropbox public URL creation script for a directory of public URLs (getdropbox.com - gpl I think). My LIST file was created using ls in the following fashion:
ls -d ~/Dropbox/Public/PUBLICFILES/* > LIST
dropboxpuburl.sh:
for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH > ~/URLLIST/$PATH
done
Now this creates a whole series of files - each with the dropbox puburl in them.
The question is: How can I cause this script to redirect all the public links into one text file, each on a new line - perhaps with the name PUBLIC-DIRECTORY-LIST?
Is this what you are trying to achieve?
for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH >> filename
done
OK, I've got it working using the suggestions given to me here:
for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH
done > PUBLIC-DIRECTORY-LIST
It creates a list of the directories, and below them the public link. Now it is time to prune the directories for a clean text file of links.
The => creates the files and adds something to the first line. >> appends to it on a new line.
echo txt=>PUBLIC-DIRECTORY-LIST.txt |
echo another text>>PUBLIC-DIRECTORY-LIST.txt
You should use while read with input redirection instead of for with cat filename. Also, in order to avoid variable name conflicts I changed your path variable to lowercase since the shell uses the all-caps one already. It won't affect your interactive shell, but it could affect something in your script.
Also, assuming that you want the lines from your input file to be displayed to the screen as a progress indicator, but not captured in your output file, this echo sends it to stderr.
while read path
do
echo $path >&2
dropbox puburl $path
done < LIST > PUBLIC-DIRECTORY-LIST