Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: NT script question ???

RE: NT script question ???

From: Reardon, Bruce (CALBBAY) <Bruce.Reardon_at_comalco.riotinto.com.au>
Date: Sun, 03 Jun 2001 16:04:23 -0700
Message-ID: <F001.00319A74.20010603155529@fatcity.com>

Andrew,

Batch parameters are referred to as %1, %2 etc %0 is the name of the calling command.
%* refers to all parameters
You can use the shift command to move parameters (do help shift)

As an example:
C:\batch>type param_test.bat
@echo off

echo %1
echo %2
echo %0
echo %*
C:\batch>

C:\batch>
C:\batch>param_test.bat one two three four five one
two
param_test.bat
one two three four five

C:\batch>
To append the date / time, use the for command to split up the output of time and date commands.

For example:

C:\batch> test_time.bat
[08504789]
[0604Mon]


@echo off
rem test_time.bat

call :get_timestamp

call :get_datestamp

goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::

:get_timestamp

        :: get the time in format hhmmssxx, where 'xx' is hundredths of a second

        :: because want ssxx can not use time/t    for /f "tokens=1-8 delims=:. " %%a in ('echo.^| time ^| find "current"') do (

       set zhh=%%e
       set zmm=%%f
       set zss=%%g
       set zxx=%%h

   )

   if 10 GTR %zhh% set zhh=0%zhh%

        :: assign the values to ztimefull    set ztimefull=%zhh%%zmm%%zss%%zxx%  

   echo [%ztimefull%]

        rem cleanup

   set zhh=
   set zmm=
   set zss=
   set zxx=

   goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::

:get_datestamp

        :: get the time in format yyyymmdd    for /f "tokens=1-8 delims=:.-/ " %%a in ('echo.^| date ^| find "current"') do (

       set zyyyy=%%h
       set zmm=%%g
       set zdd=%%f

   )

        :: assign the values to zdatefull    set zdatefull=%zyyyy%%zmm%%zdd%  

   echo [%zdatefull%]

        rem cleanup
   set zyyyy=
   set zmm=
   set zdd=

   goto :EOF

:::::::::::::::::::::::::::::::::::::::::::::::::::::::


A more useful example of parameters might be:

@echo off

rem PURPOSE
rem delete_oldfiles.bat
rem deletes files greater than or equal to x days old rem Note - directories are not deleted.

rem does not delete read only, hidden or system files

rem 18-Apr-2000 , Bruce Reardon : Creation.

rem USEAGE
rem Parameters - %1 = path , %2 = file mask , rem %3 = how many days old , %4 (optional) - recurse

rem ASSUMPTIONS
rem none.

rem REQUIRES

rem     forfiles.exe - distributed with NT Resource kit
rem     that forfiles.exe be located at c:\nt4reskit

rem SIDE EFFECTS
rem     envdelold env variable will be overwritten and deleted if it exists.

rem MODIFICATIONS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

        rem Parameter validation.

IF "%3"=="" goto param_problem :: not enough params

IF NOT "%5"=="" goto param_problem :: too many params

        rem check parameter 3 is a valid number set envdelold=
IF "%3"=="0" goto param3_ok

   set /a envdelold = 1*%3  2> nul:
   IF "%envdelold%"=="0" goto param3_problem 
   IF "%envdelold%"=="" goto param3_problem 

:param3_ok

IF NOT "%4"=="" IF NOT "%4"=="-s" goto param4_problem :: invalid param 4

IF NOT EXIST %1. goto param1_problem

        rem we now have 3 (possibly 4) parameters and they have been validated.

echo %1 %2 %3 %4

        rem the actual command - put quotes around to allow for names with spaces.

c:\nt4reskit\forfiles -p%1 -m%2 %4 -d-%3 -c"cmd /c if @ISDIR==FALSE del 0x22_at_FILE0x22"

goto end

:param_problem

   echo %0
   echo ERROR - Must pass in 3 parameters (4 max)

   echo     Param 1 is the path
   echo     Param 2 is file mask
   echo     Param 3 is number of days
   echo     Param 4 (optional) : if "-s" then recurse subdir's.
   echo.
   echo eg "%0 c:\temp *.* 5" would delete ALL files in c:\temp directory 5 or more days old

   goto end

:param1_problem

   echo "%0 [-->[%1]<--] %2 %3 %4"
   echo ERROR - 1st parameter invalid
   echo Param 1 is the path and it must exist.    echo.
   echo eg "%0 c:\temp *.* 5" would delete ALL files    echo in c:\temp directory 5 or more days old    goto end

:param3_problem

   echo "%0 %1 %2 [-->[%3]<--] %4"
   echo ERROR - 3rd parameter invalid
   echo Param 3 is the number of days and it must be a valid number    echo.
   echo eg "%0 c:\temp *.* 5" would delete ALL files    echo in c:\temp directory 5 or more days old    goto end

:param4_problem

   echo "%0 %1 %2 %3 [-->[%4]<--]"
   echo ERROR - 4th parameter invalid
   echo Param 4 (optional) : must be "-s" (to recurse subdir's) or be blank.

   echo.
   echo eg "%0 c:\temp *.* 5 -s" would delete ALL files    echo in c:\temp directory (incl subdirs) 5 or more days old    goto end

:end

   rem - batch file finished
   set envdelold=


-----Original Message-----
Sent: Sunday, 3 June 2001 9:15

Hi,

I have couple of questions about bat file in NT 4.0 for Oracle 8.1.5.

  1. how to make bat file take parameters. I had a backup.bat, and like to pass in Oracle SID, so the script can backup any database.
  2. in the bat file, how to dynamically append date/time into a directory name, like backup_06022001121314

Thank you!

Andrea

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Reardon, Bruce (CALBBAY)
  INET: Bruce.Reardon_at_comalco.riotinto.com.au

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Sun Jun 03 2001 - 18:04:23 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US