Fichier: MonitorDB.zip.
@Echo Off
rem extract the date and time to variable
rem http://www.computing.net/answers/dos/rename-file-with-date-and-increment/15614.html
For /F "tokens=*" %%A in ('Date /T') Do Set DT=%%A
rem extract time for NT
rem http://www.batchfiles.co.nr/
for /F "tokens=1-4 delims=:., " %%a in ("%TIME%") do set TM=%%a%%b%%c
rem compute filename by removing unwanted characters
rem http://www.ss64.com/nt/syntax-replace.html
rem
rem replace space (and everything before) with Empty String
set DT=%DT:* =%
rem replace all time back slashs
set DT=%DT:/=%
set DT=%DT:/=%
set DT=%DT:/=%
set DT=%DT: =%
rem Debug by outputing the value.
rem Echo DateAndTime=%DT%_%TM% > File.txt
rem --- Analyse DB1 ---
SET TargetDB=TxsDev003V403
SET OutFilename="LockInfo_%TargetDB%_%DT%_%TM%.dat"
SQLCMD -v TargetDB=%TargetDB% -S . -E -H MonitorCmd -o %OutFilename% -i monitorDB.sql
rem --- Analyse DB2 ---
SET TargetDB=PlayGround
SET OutFilename="LockInfo_%TargetDB%_%DT%_%TM%.dat"
SQLCMD -v TargetDB=%TargetDB% -S . -E -H MonitorCmd -o %OutFilename% -i monitorDB.sql
rem SQLCMD -v TargetDB="PlayGround" -S . -E -H MonitorCmd -o %OutFilename% -i monitorDB.sql
En guise de résultat, mes noms de fichiers sont:
LockInfo_PlayGround_21042009_110528.dat
LockInfo_TxsDev003V403_21042009_110528.datPour plus d'informations, voir les liens suivants:
- Remplacement de chaine de caractères dans un batch (StrToFind).
- Inclure la date dans un nom de fichier (et numéro incrémental).
- Batch File FAQ
Aucun commentaire:
Enregistrer un commentaire