Discussion:
using blat and first argument batch parameter %1%
(too old to reply)
fborup@hotmail.com [blat]
2017-03-03 18:31:54 UTC
Permalink
IÂŽm building a backup.cmd batch file and trying to use the first argument in the batch file as parameter

First i test if there is no parameter in batch file name:

if "%1" == "" goto END

so, every time the bath is used, i have to put a first argument, in my case, a 3-letter acronym like “abc” or “xyz”

the command line is:

blat - -body "ERRO - %ROTINA%" -server %SMTPSERVER% -to %CXPOSTAL% -f %COMPUTERNAME%%@%DESTDOMAIN% -subject "Backup OFFSHORE MAXIMO em %DATE% de %COMPUTERNAME%"


this example above Works well, but...

if i try to use:


-subject "Backup OFFSHORE MAXIMO de %1% em %DATE%”

Thing get weird!,

the subject is changed to “Contents of file: bakora_MAXIMO_sex_als.LOG” insted my custom subject


But..

If i try to use %1% as the last parameter, things got more weird:

Using -subject "Backup OFFSHORE MAXIMO em %DATE% de %1%”, the subject “concatenates” the %1% variable and add a lot of other variables in the batch file and the subject goes like that:

Backup OFFSHORE MAXIMO em sex, 03/03/2017 de SERVERNAME alsRCLOGFILEZIPLOGFILEBAKEXPDUMPLOGFILE

In the case above, the %1% first argument paramenter/variable, is “als” and the other strings are arbitrary strings/variables of my batch file, not even make sense, because some variables are not the first in the batch file...

Why canÂŽt i use the %1% first argument of the batch file as variable in blat command line?

Blat v2.6.2 w/GSS encryption (build : Feb 25 2007 12:06:19)



===================== FULL BATCH ====================================================


@echo off
cls

if "%1" == "" goto END

; rem ********************* WISH LIST ************************************************
; rem To be able to use %1% as variable inside BLAT command line
; rem When i try to add %1% in the subject, blat puts weird string
; rem alsRCLOGFILEZIPLOGFILEBAKEXPDUMPLOGFILE
; rem ********************* WISH LIST ************************************************

echo.
echo.
set ROTINA=Backup local Maximo - Versao 6.4fb
echo.
echo.
echo Variaveis de Dominio, SMTP
set DESTDOMAIN=mymaildomain.com
set SMTPSERVER=smtp.%DESTDOMAIN%
set PAUSETIMEOUT=15
set COMPRESSIONLEVEL=1

echo.
echo.
echo Variaveis de MAIL e PLATAFORMA
set CXPOSTAL=sup@%DESTDOMAIN%

echo.
echo.
echo Definindo variaveis de ambiente
echo.
echo.
echo Variaveis de Data
set dd=%DATE:~5,2%
set mm=%DATE:~8,2%
set yyyy=%DATE:~11,4%
set DIASEMANA=%DATE:~0,3%
echo %DIASEMANA%,%dd%-%mm%-%yyyy%


echo.
echo.
echo Variaveis de Caminhos
set BAKFOLDER=C:\DADOS\BACKUP
set BAKORAPATH=E:\bkpmaximo\DUMP
set BAKDOCLINKS=E:\DOCLINKS

echo.
echo.
echo Variaveis de DUMP/ZIP
set BAKORADESTINATION=\\BR%1%-SRV0003\ARQUIVOS\UTIL\BACKUP
set BAKORADUMPNAME=MAXIMO_EXP_DUMP_ORACLE_%DIASEMANA%_%1%.DMP
set BARORAZIP=%BAKFOLDER%\BAKORA_MAXIMO_ZIP_%DIASEMANA%_%1%.ZIP

echo.
echo.
echo Variaveis de LOGs
set BAKEXPDUMPLOGFILE=MAXIMO_LOG_EXP_DUMP_ORACLE_INFO_%DIASEMANA%_%1%.LOG
set BAKORALOGFILE=%BAKFOLDER%\bakora_MAXIMO_%DIASEMANA%_%1%.LOG
set RCLOGFILE=%BAKFOLDER%\bakora_robocopy_%DIASEMANA%_%1%.LOG
set ZIPLOGFILE=%BAKFOLDER%\bakora_7ZIP_%DIASEMANA%_%1%.LOG

echo.
echo.
echo Validation Tests I - e:\bkpmaximo\dump c:\dados\backup c:\dados\scripts
if not exist e:\bkpmaximo\dump\*.* goto ERRO
if not exist c:\dados\backup\*.* goto ERRO
if not exist c:\dados\scripts\*.* goto ERRO

echo.
echo.
echo Validation Tests II - %BAKDOCLINKS% %BAKORADESTINATION% %BAKORADESTINATION%\ORACLE %BAKORADESTINATION%\DOCLINKS
if not exist %BAKDOCLINKS%\*.* goto ERRO2
if not exist %BAKORADESTINATION%\*.* goto ERRO2
if not exist %BAKORADESTINATION%\ORACLE\*.* goto ERRO2
if not exist %BAKORADESTINATION%\DOCLINKS\*.* ERRO2


cd /d %BAKORAPATH%

echo.
echo.
echo Apagando arquivos antigos caso existam
if exist %BAKORADUMPNAME% del %BAKORADUMPNAME%
if exist %BAKEXPDUMPLOGFILE% del %BAKEXPDUMPLOGFILE%
if exist %BARORAZIP% del %BARORAZIP%
if exist %BAKORALOGFILE% del %BAKORALOGFILE%
if exist %RCLOGFILE% del %RCLOGFILE%
if exist %ZIPLOGFILE% del %ZIPLOGFILE%


echo.
echo.
echo Exportando
echo.
echo.
set ORACLE_SID=orcl
expdp datapumpuser/datapumpwd FULL=Y dumpfile=DUMP_MAXIMO:%BAKORADUMPNAME% logfile=DUMP_LOG:%BAKEXPDUMPLOGFILE% ESTIMATE=STATISTICS
timeout %PAUSETIMEOUT%
echo.
echo.
echo Zipando o Export
echo.
echo.
7za a -mx%COMPRESSIONLEVEL% %BARORAZIP% %BAKORADUMPNAME% > %ZIPLOGFILE%
timeout %PAUSETIMEOUT%



echo.
echo.
echo Copiando o DB Zipado
echo.
echo.
robocopy %BAKORAPATH% %BAKORADESTINATION%\ORACLE *.dmp *.log /r:2 /w:2 /np /mir > %RCLOGFILE%
robocopy %BAKORAPATH% %BAKORADESTINATION%\ORACLE *.zip *.log /r:2 /w:2 /np /mir >> %RCLOGFILE%
robocopy %BAKDOCLINKS% %BAKORADESTINATION%\DOCLINKS /s /r:2 /w:2 /np /mir >> %RCLOGFILE%
robocopy C:\DADOS\SCRIPTS %BAKORADESTINATION% /s /r:2 /w:2 /np >> %RCLOGFILE%


echo.
echo.
echo Gerando Listagem de conteudo
echo.
echo.
cd /d c:\dados\BACKUP

echo.
echo.
echo Gerando Listagem de conteudo do LOG ORACLE
echo JOBSTATUS > %BAKORALOGFILE%
echo. >> %BAKORALOGFILE%
type c:\dados\BACKUP\%BAKEXPDUMPLOGFILE% | find "job" >> %BAKORALOGFILE%
echo. >> %BAKORALOGFILE%

echo.
echo.
echo Gerando Listagem de conteudo dos DUMPs

echo DUMPLOCAL em %BAKORAPATH% >> %BAKORALOGFILE%
dir /o-d %BAKORAPATH%\*.DMP | find /i ".dmp" >> %BAKORALOGFILE%
echo. >> %BAKORALOGFILE%

echo DUMPREMOTO em %BAKORADESTINATION%\ORACLE >> %BAKORALOGFILE%
dir /o-d %BAKORADESTINATION%\ORACLE | find /i ".dmp" >>%BAKORALOGFILE%
echo. >> %BAKORALOGFILE%

echo 7za t %BARORAZIP%
7za t %BARORAZIP% | find /v "Copyright" >> %BAKORALOGFILE%
echo. >> %BAKORALOGFILE%
timeout %PAUSETIMEOUT%


echo.
echo.
echo Enviando E-Mails com os Logs de Backup anexados to %CXPOSTAL%
blat %BAKORALOGFILE% -server %SMTPSERVER% -to %CXPOSTAL% -f %COMPUTERNAME%@%DESTDOMAIN% -subject "Backup OFFSHORE MAXIMO em %DATE% de %COMPUTERNAME%" -attach %RCLOGFILE% -attach %ZIPLOGFILE% -attach %BAKEXPDUMPLOGFILE%
goto END

:ERRO2
echo.
echo.
blat - -body "ERRO - %ROTINA% - Erro de diretorio REMOTO" -server %SMTPSERVER% -to %CXPOSTAL% -f %COMPUTERNAME%%@%DESTDOMAIN% -subject "Backup OFFSHORE MAXIMO em %DATE% de %COMPUTERNAME% - Erro de diretorio REMOTO"
goto END


:ERRO
echo.
echo.
blat - -body "ERRO - %ROTINA% - Erro de diretorio LOCAL" -server %SMTPSERVER% -to %CXPOSTAL% -f %COMPUTERNAME%@%DESTDOMAIN% -subject "Backup OFFSHORE MAXIMO em %DATE% de %COMPUTERNAME% - Erro de diretorio LOCAL"

:END
cd /d c:\dados\scripts


===================== FULL BATCH ====================================================
Continue reading on narkive:
Loading...