Re: script log file (how)



I didn't know "is larger than" and "size" were shell key words until now.
I'll test it out when I get a chance. Maybe I'll just have the script
create log archives after they grow to a certain size and purge the oldest
logs after a certain point (maybe one working log and one archive).
Thanks.

"Jeffery Hicks" <"jhicks[at]SAPIEN.com"> wrote in message
news:1g93k4j4f4ot3.1cgtxp906f14s.dlg@xxxxxxxxxxxxx
On Thu, 25 Jan 2007 20:06:25 -0800, Steven wrote:

I have a DOS batch file I use for backing up certain files and then
burning
them to DVD's using nero once a week.
The problem with my original script was that it didn't keep any logs of
what
it did and/or when it fails. If anything fails I had to investigate it
manually (time consuming).

I've since modified it to redirect any "console" output to a text file
and
inserted "you are here" type ECHO's throught the script. The output also
creates a new log file every year so a single log file doesn't get too
big
if no one ever purges it. Now I have a record of the previous 1 to 52
runs
but the logs eventually take up space and become difficult to work with.

I want to modify the script to maintain a single log file and purge old
records as needed. I want it to be self contained and not grow out of
control.

Q1: Is there an easy way to keep an ongoing record of previous runs in a
log
file AND also prevent the log file from ballooning into a huge file (I
want
it be a maximum size of 1 MB, or only keep a certain number of runs if
possible)?

Here is a snippet of the script I run (working portions removed for
brevity):
[start]
echo start
echo copy files into archive
echo burn archive using nerocmd.exe
echo done
[end]

command= c:\scripts\burnit.bat >> burnit_log_%date:~10,4%.txt

Result:
-creates a "burnit_log_2007.txt" file and appends all output that would
normally be printed to the screen during each run
-burnit_log_2007.txt can grow to a large size if problems are encountered
or
the file is never purged

That's going to be difficult to do with a batch file. There isn't an easy
way to treat the text file as a database which is what it seems you're
trying to do. Now you could check the size of the file and if exceeds a
specified threshold, then whack it and start a new one. Here's an old
batch file that takes a filename and size as parameters. If the file size
exceeds the parameter it displays a message.

@echo off
::CHKSIZE.BAT
if %1$==$ GOTO :Error
if %2$==$ GOTO :Error

SET TARGET=%1
SET SIZE=%2

for /f "tokens=2 delims=)" %%i in ('dir /-c %TARGET% ^|find /i
"bytes"^|find /v
/i "free"') do @set Z=%%i

for /f "tokens=1 delims=b" %%i in ('echo %z%') do @set Z=%%i

if %Z% GEQ %SIZE% ECHO %TARGET% is larger than %SIZE% bytes
REM instead of GEQ you could substitute:
REM use LEQ for less than or equal to
REM use EQU for equal to
REM use LSS for less than
REM use GTR for greater than
SET TARGET=
SET SIZE=
SET Z=
GOTO :EOF

:ERROR
Echo Missing Parameter!
echo USAGE: %0 filename size_threshold_bytes
echo Example %0 c:\files\log.txt 1024

:EOF



--
Jeffery Hicks
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
VBScript & Windows PowerShell Training -
www.ScriptingTraining.com/classes.asp
Windows PowerShell? - www.SAPIENPress.com/powershell.asp

blog: http://blog.SAPIEN.com
blog: http://jdhitsolutions.blogspot.com


.



Relevant Pages

  • Re: script log file (how)
    ... The problem with my original script was that it didn't keep any logs of what ... echo copy files into archive ... if %1$==$ GOTO:Error ... REM instead of GEQ you could substitute: ...
    (microsoft.public.windows.server.scripting)
  • RE: Help for Windows Vista.
    ... just add a username and password to your command. ... Echo Loggin into our company ... REM *** drev w ... Did you run the Script as Administrator? ...
    (microsoft.public.windows.vista.general)
  • Re: COMMAND SHELL PROGRAMMING.
    ... The first comment claims to get user's input but never prompts for ... Another comment claims to delete the script file but only empties it. ... Long ago I read:REM is quicker then REM. ... Echo some text here>outputfile.txt ...
    (bit.listserv.ibm-main)
  • Re: Printer Starup Script successfull for Win2k, but not for XP
    ... So I used the NT Resource Kit file "con2prt.exe" and the following script: ... @echo off ... REM Script is to set up printers on users ... REM workstations ...
    (microsoft.public.windows.server.scripting)
  • Re: [Full-disclosure] reduction of brute force login attempts via SSHthrough iptables --
    ... Anyhow its no problem at all to modify, so if you dont like it, just dont use it. ... on a lame script like this as long as it WORKS and is not insecure. ... echo "~ sorting out ip by ip" ... # echo "not enough failed logins, probably no attack from: ...
    (Full-Disclosure)