freebies are awesome
this junk comes in handy!
I have been doing Help Desk and Network Adminstration for many years and they say necessity is the mother of invention. Over the years I have have created scripts which have proven very useful and I want to share them and get feedback.
-------------------------
Currently working on script to perform off-line defrags of Exchange dbases
-------------------------
This one is a text based ticket tracker - for the help-desk folks.
Used if using a ticketing system that creates tickets that use the year number as the 1st part of the ticket number, for example:
200700542 -or- 200723456.
@echo off
@cls
@color 2f
title=Text-based Ticket Tracker
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM Ticket tracking script
REM -----------------------------------------------------------------------------
REM This program will do the following (algorithm)
:: 1. Check to see in a Monthly log for the current month exists
:: if not, create one
:: 2. Check to see if previous day was finalized, if not it will finalize the previous day first
:: if previous day was end of last month, finalize to last month's log
:: 3. Check if you entered 'review'
:: if you did, open current Monthly ticket log
:: 4. Check if you entered 'count'
:: Check if daily ticket log exists, if not display error, then exit
:: if you did, count number of tickets listed in daily log and display it on the screen
:: 5. Check if you entered 'done'
:: Check if daily ticket log exists, if not display error, then exit
:: if you did, total number of tickets from daily log,
:: then enter this number in the monthly log, then delete the daily log
:: 6. Check to see if Daily ticket log exists, if not create one
:: 7. Check to see if entry matches what was already entered into daily log,
:: if does, display error (error check), if not enter it into daily log
REM Does not query Remedy!!!
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
REM -----------------------------------------------------------------------------
:start
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
set switch=0
set date=%mm%-%dd%-%yyyy%
set file=ticket%mm%
set /A cc=%dd%-1
set /A ll=%mm%-1
set count=0
if %ll% LSS 10 (set pfile=ticket0%ll%) ELSE set pfile=ticket%ll%
set /A foldr=%yyyy%-2000
set /A dd=%dd%*1
if NOT EXIST c:\ticketcount\%foldr% md c:\ticketcount\%foldr%
:roll-back
rem ------------------------------------------------------------------------------
rem Since there is no 0 day in a month, this wll give it the last day of the ..
rem previous month, if cc winds up being equal to 0.
rem ------------------------------------------------------------------------------
if %cc%==0 if %mm%==01 set cc=31&& set switch=1
if %cc%==0 if %mm%==02 set cc=31&& set switch=1
if %cc%==0 if %mm%==03 set cc=28&& set switch=1
if %cc%==0 if %mm%==04 set cc=31&& set switch=1
if %cc%==0 if %mm%==05 set cc=30&& set switch=1
if %cc%==0 if %mm%==06 set cc=31&& set switch=1
if %cc%==0 if %mm%==07 set cc=30&& set switch=1
if %cc%==0 if %mm%==08 set cc=31&& set switch=1
if %cc%==0 if %mm%==09 set cc=31&& set switch=1
if %cc%==0 if %mm%==10 set cc=30&& set switch=1
if %cc%==0 if %mm%==11 set cc=31&& set switch=1
if %cc%==0 if %mm%==12 set cc=30&& set switch=1
rem ------------------------------------------------------------------------------
if EXIST c:\ticketcount\%foldr%\temp-%cc%.txt set dd=%cc%&& goto beforedone
set /A cc=%cc%-1
set /A count=%count%+1
if %count% LSS 5 goto roll-back
set /P ticket=Enter 'Ticket Number', 'count', 'Done' or 'Review'...
rem ------------------------------------------------------------------------------
:doccheck
if NOT EXIST c:\ticketcount\%foldr%\%file%.txt goto ticketcount
if /I %ticket%==Review goto review
if /I %ticket%==count goto tcounter
if /I %ticket%==Done goto done
rem ------------------------------------------------------------------------------
rem Input validation - at the very least makes sure that the 4-digit year is ...
rem at the first part of the input
rem since in Remedy thats how the tickets are numbered
rem ------------------------------------------------------------------------------
if NOT EXIST c:\temp md c:\temp
set tempticket= %ticket%
echo %tempticket% > c:\temp\temp.txt
FOR /F "tokens=1* delims= " %%A IN ('find /C " %yyyy%" c:\temp\temp.txt') DO SET tcount=%%B
FOR /F "tokens=2,3 delims=:" %%A IN ('set tcount') DO SET tcount=%%B
if %tcount%==0 del c:\temp\temp.txt && echo Must enter the full ticket number && pause && cls && goto start
del c:\temp\temp.txt
if NOT EXIST c:\ticketcount\%foldr%\temp-%dd%.txt goto tempticket
goto repeat
:enter
echo %ticket% >> c:\ticketcount\%foldr%\%file%.txt
echo %ticket% >> c:\ticketcount\%foldr%\temp-%dd%.txt
goto end
rem ------------------------------------------------------------------------------
:ticketcount
echo. > c:\ticketcount\%foldr%\%file%.txt
goto doccheck
:tempticket
echo. >> c:\ticketcount\%foldr%\%file%.txt
echo %cdate% >> c:\ticketcount\%foldr%\%file%.txt
echo ------- >> c:\ticketcount\%foldr%\%file%.txt
echo. > c:\ticketcount\%foldr%\temp-%dd%.txt
goto doccheck
:tcounter
if NOT EXIST c:\ticketcount\%foldr%\temp-%dd%.txt echo NO tickets have been entered yet!! && pause && goto end
FOR /F "tokens=1* EOL=" %%A IN ('find /C "%yyyy%" c:\ticketcount\%foldr%\temp-%dd%.txt') DO SET tcount=%%B
FOR /F "tokens=2,3* delims=:" %%A IN ('set tcount') DO SET tcount=%%B
echo Tickets closed for %date%: %tcount% && pause
goto end
:done
if NOT EXIST c:\ticketcount\%foldr%\temp-%dd%.txt echo NO tickets have been entered yet!! && pause && goto end
FOR /F "tokens=1* EOL=" %%A IN ('find /C "%yyyy%" c:\ticketcount\%foldr%\temp-%dd%.txt') DO SET tcount=%%B
FOR /F "tokens=2,3* delims=:" %%A IN ('set tcount') DO SET tcount=%%B
set /A tcount=%tcount% * 1
echo ------------ >> c:\ticketcount\%foldr%\%file%.txt
echo Total: [%tcount%] >> c:\ticketcount\%foldr%\%file%.txt
start /wait notepad c:\ticketcount\%foldr%\temp-%dd%.txt
del c:\ticketcount\%foldr%\temp-%dd%.txt
goto end
:review
echo The following monthly logs found:
if EXIST c:\ticketcount\%foldr%\ticket01.txt echo January
if EXIST c:\ticketcount\%foldr%\ticket02.txt echo February
if EXIST c:\ticketcount\%foldr%\ticket03.txt echo March
if EXIST c:\ticketcount\%foldr%\ticket04.txt echo April
if EXIST c:\ticketcount\%foldr%\ticket05.txt echo May
if EXIST c:\ticketcount\%foldr%\ticket06.txt echo June
if EXIST c:\ticketcount\%foldr%\ticket07.txt echo July
if EXIST c:\ticketcount\%foldr%\ticket08.txt echo August
if EXIST c:\ticketcount\%foldr%\ticket09.txt echo September
if EXIST c:\ticketcount\%foldr%\ticket10.txt echo October
if EXIST c:\ticketcount\%foldr%\ticket11.txt echo November
if EXIST c:\ticketcount\%foldr%\ticket12.txt echo December
echo Which month do you want to review?
set /P answer=Type name of month, 3-letter equivalent, or (C) for current?
if /I %answer%==January (set mnumb=01) ELSE if /I %answer%==jan set mnumb=01
if /I %answer%==February (set mnumb=02) ELSE if /I %answer%==Feb set mnumb=02
if /I %answer%==March (set mnumb=03) ELSE if /I %answer%==mar set mnumb=03
if /I %answer%==April (set mnumb=04) ELSE if /I %answer%==apr set mnumb=04
if /I %answer%==May set mnumb=05
if /I %answer%==June set mnumb=06
if /I %answer%==July set mnumb=07
if /I %answer%==August (set mnumb=0
ELSE if /I %answer%==aug set mnumb=08
if /I %answer%==September (set mnumb=09) ELSE if /I %answer%==sep set mnumb=09
if /I %answer%==October (set mnumb=10) ELSE if /I %answer%==oct set mnumb=10
if /I %answer%==November (set mnumb=11) ELSE if /I %answer%==nov set mnumb=11
if /I %answer%==December (set mnumb=12) ELSE if /I %answer%==dec set mnumb=12
if /I %answer%==c (start /wait notepad c:\ticketcount\%foldr%\%file%.txt) ELSE (start /wait notepad c:\ticketcount\%foldr%\ticket%mnumb%.txt)
goto end
:end
exit
REM ------------------------------------------------------------------------------
REM ------------------------ ERROR CHECKING --------------------------------------
REM ------------------------------------------------------------------------------
:beforedone
rem ------------------------------------------------------------------------------
REM Say at the end of the day either because your in a hurry (or whatever)..
rem and you forget to type 'Done' and the previous day's ticket file..
rem is still there. This will finalize the previous day and delete that file for you.
rem ------------------------------------------------------------------------------
FOR /F "tokens=1* EOL=" %%A IN ('find /C "%yyyy%" c:\ticketcount\%foldr%\temp-%dd%.txt') DO SET tcount=%%B
FOR /F "tokens=2,3* delims=:" %%A IN ('set tcount') DO SET tcount=%%B
set /A tcount=%tcount% * 1
if %switch%==1 echo ------------ >> c:\ticketcount\%foldr%\%pfile%.txt
if %switch%==1 echo Total: [%tcount%] >> c:\ticketcount\%foldr%\%pfile%.txt
if %switch%==0 echo ------------ >> c:\ticketcount\%foldr%\%file%.txt
if %switch%==0 echo Total: [%tcount%] >> c:\ticketcount\%foldr%\%file%.txt
del c:\ticketcount\%foldr%\temp-%dd%.txt
goto start
rem ------------------------------------------------------------------------------
:repeat
rem ------------------------------------------------------------------------------
rem This part will prevent repeat entries. Same ticket number being entered twice
rem ------------------------------------------------------------------------------
FOR /F "tokens=1 delims=" %%A IN ('find /C "%ticket% " c:\ticketcount\%foldr%\temp-%dd%.txt') DO SET tcount=%%A
FOR /F "tokens=2,3* delims=:" %%A IN ('set tcount') DO SET tcount=%%B
if %tcount% NEQ 0 echo Ticket has already been entered!! && pause && cls && goto start
goto enter

Chowhound
Comic Vine
GameFAQs
GameSpot
Giant Bomb
TechRepublic