FAQ
Does anybody know of a site that is good for translating unix shell scripts
into Windows batch files? I have two rman scripts that I want to run on a
windows server.

thanks.

Don�t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Search Discussions

  • David Sharples at Jul 19, 2006 at 5:13 pm
    you could install cygwin and not have to change anything if you wish

    On 19/07/06, Joe Smith wrote:

    >
    Does anybody know of a site that is good for translating unix shell
    scripts
    into Windows batch files? I have two rman scripts that I want to run on a
    windows server.
    --
    http://www.freelists.org/webpage/oracle-l
  • Jared Still at Jul 19, 2006 at 5:21 pm
    I would be very surprised if such a site/tool existed.

    Any shell script of moderate complexity would be
    very difficult to translate to windows batch scripting
    via automated facility.

    What can be done with 1 or 2 lines in shell often
    takes many lines of code in windows.

    eg. A one liner in shell. Get a filename with a date stamp.
    jkstill-0 > f='myfile_'$(date +%Y-%m-%d)
    jkstill-0 > echo $f
    myfile_2006-07-19

    Doing this in Windows requires several lines of vbscript and
    temporary files.

    If you really need to run the shell scripts in Windows, consider using
    Cygwin.

    Or just rewrite them.
    On 7/19/06, Joe Smith wrote:

    Does anybody know of a site that is good for translating unix shell
    scripts
    into Windows batch files? I have two rman scripts that I want to run on a
    windows server.

    thanks.

    _________________________________________________________________
    Don't just search. Find. Check out the new MSN Search!
    http://search.msn.click-url.com/go/onm00200636ave/direct/01/

    --
    http://www.freelists.org/webpage/oracle-l

    --
    Jared Still
    Certifiable Oracle DBA and Part Time Perl Evangelist

    --
    http://www.freelists.org/webpage/oracle-l
  • Alex Gorbachev at Jul 19, 2006 at 6:39 pm
    I am surprised! Where is your advice about Perl??;-)

    2006/7/19, Jared Still :
    If you really need to run the shell scripts in Windows, consider using
    Cygwin.
    --
    Best regards,
    Alex Gorbachev

    http://blog.oracloid.com
    --
    http://www.freelists.org/webpage/oracle-l
  • Ganesh Raja at Jul 19, 2006 at 6:52 pm
    BTW WSU Provides active perl with the Install.

    I dont usually advocate MS Products but this really takes the cake :)

    Ganesh
    On 7/19/06, Alex Gorbachev wrote:

    I am surprised! Where is your advice about Perl??;-)

    2006/7/19, Jared Still :
    If you really need to run the shell scripts in Windows, consider using
    Cygwin.


    --
    Best regards,
    Alex Gorbachev

    http://blog.oracloid.com
    --
    http://www.freelists.org/webpage/oracle-l

    --
    -----------------------------------------------------------
    http://iyertalks.blogspot.com/

    --
    http://www.freelists.org/webpage/oracle-l
  • Jared Still at Jul 20, 2006 at 12:54 am

    On 7/19/06, Alex Gorbachev wrote:
    I am surprised! Where is your advice about Perl??;-)
    You are the second person to express shock, surprise and dismay
    that I did not tell the OP to use Perl.

    Well, of course I should have.

    Here it is: Use Perl!

    Much more powerful than VBScript.

    CMD batch language? No point in comparing it to Perl.

    I have been learning to use some of the VB Script simply because
    it is require in some cases. (built in language for some tools)

    --
    Jared Still
    Certifiable Oracle DBA and Part Time Perl Evangelist

    --
    http://www.freelists.org/webpage/oracle-l
  • Steve Perry at Jul 20, 2006 at 2:10 am
    that only takes 2 lines :)))

    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19

    seriously though.

    Jared, and others, have already mentioned using perl and cygwin.
    Perl works great between linux and windonts. I use the same script to
    monitor the alertlog on windows and linux.
    if you really want to use a batch script, download the win32 unix
    ports of grep, sed, awk, cat, wc, tail, tee.... I have a lot of them
    and used to write some interesting scripts. They were easy to install
    (i.e. copy ) and eased the pain of cli. the downside is they're only
    "duct tape". I don't think they're updated anymore so it buys you
    some time until the "new guy" takes over your scripts;)

    post or email what you want to translate. This is a great place for
    help.

    my 2¢
    On Jul 19, 2006, at 12:21 PM, Jared Still wrote:

    I would be very surprised if such a site/tool existed.

    Any shell script of moderate complexity would be
    very difficult to translate to windows batch scripting
    via automated facility.

    What can be done with 1 or 2 lines in shell often
    takes many lines of code in windows.

    eg. A one liner in shell. Get a filename with a date stamp.
    jkstill-0 > f='myfile_'$(date +%Y-%m-%d)
    jkstill-0 > echo $f
    myfile_2006-07-19

    Doing this in Windows requires several lines of vbscript and
    temporary files.

    If you really need to run the shell scripts in Windows, consider
    using Cygwin.

    Or just rewrite them.


    On 7/19/06, Joe Smith wrote:
    Does anybody know of a site that is good for translating unix shell
    scripts
    into Windows batch files? I have two rman scripts that I want to
    run on a
    windows server.

    thanks.

    _________________________________________________________________
    Don't just search. Find. Check out the new MSN Search!
    http://search.msn.click-url.com/go/onm00200636ave/direct/01/

    --
    http://www.freelists.org/webpage/oracle-l





    --
    Jared Still
    Certifiable Oracle DBA and Part Time Perl Evangelist
    --
    http://www.freelists.org/webpage/oracle-l
  • Jared Still at Jul 20, 2006 at 9:09 pm

    On 7/19/06, Steve Perry wrote:
    that only takes 2 lines :)))

    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19
    First time I have seen that.

    Clearly I need to read some up to date docs on the CMD shell next time I try
    to use it.

    --
    Jared Still
    Certifiable Oracle DBA and Part Time Perl Evangelist

    --
    http://www.freelists.org/webpage/oracle-l
  • Greg Norris at Jul 21, 2006 at 5:12 pm

    On 7/19/06, Steve Perry wrote:
    that only takes 2 lines :)))

    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19
    On a semi-related note, is there any way (using "pure" cmd.exe) to
    identify files older than say, 5 days? For example, something similar
    to "find . -name "myfile\* -mtime +5".

    Unfortunately I'm not allowed to add additional software, so the use
    of add-on tools like cygwin/perl/etc. simply isn't an option. :(

    --
    "I'm too sexy for my code." - Awk Sed Fred.
    --
    http://www.freelists.org/webpage/oracle-l
  • Radoulov, Dimitre at Jul 21, 2006 at 8:57 pm

    On a semi-related note, is there any way (using "pure" cmd.exe) to
    identify files older than say, 5 days? For example, something similar
    to "find . -name "myfile\* -mtime +5".

    Unfortunately I'm not allowed to add additional software, so the use
    of add-on tools like cygwin/perl/etc. simply isn't an option. :(
    Check forfiles (tinyurl.com/r2lap) or see this link for batch scripting (not
    elegant at all) solutions.

    tinyurl.com/s29ug

    Regards
    Dimitre
  • Steve Perry at Jul 22, 2006 at 2:39 pm
    not to violate your security policies, but I think 10g installs perl
    under it's home. Why not use those binaries for your perl scripts.
    use the find2perl (may not come with oracle's distro) and you get a
    "find" perl script written for your needs.
    I haven't tried it, but it should work.

    steve
    On Jul 21, 2006, at 12:12 PM, Greg Norris wrote:
    On 7/19/06, Steve Perry wrote:

    that only takes 2 lines :)))

    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19
    On a semi-related note, is there any way (using "pure" cmd.exe) to
    identify files older than say, 5 days? For example, something similar
    to "find . -name "myfile\* -mtime +5".

    Unfortunately I'm not allowed to add additional software, so the use
    of add-on tools like cygwin/perl/etc. simply isn't an option. :(

    --
    "I'm too sexy for my code." - Awk Sed Fred.
    --
    http://www.freelists.org/webpage/oracle-l
    --
    http://www.freelists.org/webpage/oracle-l
  • Niall Litchfield at Jul 22, 2006 at 9:37 pm
    The script below is vbscript which will do what you want. No add-on's
    required (unless you are on an unsupported OS like NT4).

    Rem *****************************************
    Rem * This script deletes archive log files *
    rem * which are more than old *
    Rem * From archive log directory *
    Rem * *
    Rem *****************************************

    Rem

    Rem *****************************************
    Rem * Version History: *
    Rem * 0.1 Niall Litchfield 29/08/2003 *
    Rem *****************************************

    ' Constants alter if necessary
    const iDays = 7 ' Change this to change archive retention period
    const arch_dest = ""

    dim today,arch_date

    today = Now()
    arch_date = today - iDays

    DeleteArchives arch_dest,arch_date

    Sub DeleteArchives(strFolder,modDate)
    ' sub routine to delete archives older than
    ' modDate. Called twice

    Dim fileSystem ' Filesystem Object
    Dim folder ' Folder
    Dim file ' File Object

    ' Create the filesystem object
    set filesystem = createobject("Scripting.FileSystemObject")
    ' get the Folder
    set folder = fileSystem.GetFolder( strFolder)
    ' create a file enumerator
    For each filename in folder.files
    ' get file object
    set file = fileSystem.GetFile( fileName)
    ' get date last modified
    dateLastModified = file.DateLastModified

    ' if file is older than NUMBER_OF_DAYS
    if dateLastModified < modDate then
    fileSystem.DeleteFile (fileName)
    end if

    next
    End Sub
    On 7/21/06, Greg Norris wrote:
    On 7/19/06, Steve Perry wrote:

    that only takes 2 lines :)))

    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19
    On a semi-related note, is there any way (using "pure" cmd.exe) to
    identify files older than say, 5 days? For example, something similar
    to "find . -name "myfile\* -mtime +5".

    Unfortunately I'm not allowed to add additional software, so the use
    of add-on tools like cygwin/perl/etc. simply isn't an option. :(

    --
    "I'm too sexy for my code." - Awk Sed Fred.
    --
    http://www.freelists.org/webpage/oracle-l

    --
    Niall Litchfield
    Oracle DBA
    http://www.orawin.info

    --
    http://www.freelists.org/webpage/oracle-l
  • Guang Mei at Jul 19, 2006 at 5:28 pm
    Hi Joe,


    I recently converted some DOS batch scripts to Linux Shell scripts. I found the easiest way is to re-write them. I have not found any tools to do that kind of conversion back and forth.


    Guang

    On 7/19/06, Joe Smith < joe_dba_at_hotmail.com> wrote:

    Does anybody know of a site that is good for translating unix shell scripts
    into Windows batch files? I have two rman scripts that I want to run on a
    windows server.

    thanks.
  • Ganesh Raja at Jul 19, 2006 at 6:41 pm
    Just Piggy Backing here .. If you are a Windows Windows Shop Go for Windows
    Services for UNIX Very well done and as good as Cygwin.

    Cheers
    Ganesh
    On 7/19/06, Guang Mei wrote:

    Hi Joe,

    I recently converted some DOS batch scripts to Linux Shell scripts. I
    found the easiest way is to re-write them. I have not found any tools to do
    that kind of conversion back and forth.

    Guang



    On 7/19/06, Joe Smith wrote:

    Does anybody know of a site that is good for translating unix shell
    scripts
    into Windows batch files? I have two rman scripts that I want to run on
    a
    windows server.

    thanks.
    --
    -----------------------------------------------------------
    http://iyertalks.blogspot.com/

    --
    http://www.freelists.org/webpage/oracle-l
  • Sweetser, Joe at Jul 22, 2006 at 12:35 am
    Had to resend...hope it formats OK. I can send the script to anyone offline, just email me...after next Tuesday...off to Alaska for a few days.

    -joe
    http://www.peaceaday.com

    -----Original Message-----
    From: Sweetser, Joe
    Sent: Fri 7/21/2006 10:27 AM
    To: spikey.mcmarbles_at_gmail.com; ORACLE-L
    Subject: RE: batch file scripting


    As always, YMMV and test.



    Usage: <# days to delete files older than (?)> :-)



    Good luck,

    -joe

    http://www.peaceaday.com <http://www.peaceaday.com/>



    ::-----------------------------------------------------------------------------------

    ::-- DeleteOldDirFiles directory daysold

    ::

    :: This has been tested on 2000 and XP. There are differences in the two systems,

    :: (see code below) so other OS's may also be different.

    ::-----------------------------------------------------------------------------------



    @ECHO OFF

    REM.-- Prepare the Command Processor

    SETLOCAL ENABLEEXTENSIONS

    SETLOCAL ENABLEDELAYEDEXPANSION



    REM get the OS Version (for different syntaxes later)

    for /f "tokens=3 usebackq" %%V in (`ver`) do set OSVERSION=%%V%



    if '%1%' EQU '' (

    echo Directory not specified

    echo Usage: DeleteOldDirFiles "directory" daysold

    GOTO:EOF

    )



    if '%2%' EQU '' (

    echo DaysOld not specified

    echo Usage: DeleteOldDirFiles "directory" daysold

    GOTO:EOF

    )



    if '%3%' NEQ '' (

    echo Too many arguments

    echo Usage: DeleteOldDirFiles "directory" daysold

    GOTO:EOF

    )



    set DELDIR="%1%"

    set DAYSOLD=%2%

    echo Deleting files in directory "%DELDIR%" older than %DAYSOLD% days old.



    REM determine today's date and convert it into julian days

    for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set /a Y1=1%%c-10000&set /a M1=1%%a-100&set /a D1=1%%b-100

    call:date2jdate JD1 Y1 M1 D1

    rem echo JD1 is %JD1%; Y1 is %Y1%; M1 is %M1%; D1 is %D1%



    REM delete files older than d days for each file in the specified directory

    for /r "%DELDIR%" %%f in (*) do (

    REM determine the date of the file

    if "%OSVERSION%" EQU "XP" (

    for /f "tokens=1-3 delims=/ " %%a in ("%%~tf") do set /a Y2=1%%c-10000&set /a M2=1%%a-100&set /a D2=1%%b-100

    )

    if "%OSVERSION%" EQU "2003" (

    for /f "tokens=1-3 delims=/ " %%a in ("%%~tf") do set /a Y2=1%%c-10000&set /a M2=1%%a-100&set /a D2=1%%b-100

    )

    if "%OSVERSION%" EQU "2000" (

    for /f "tokens=1-3 delims=/ " %%a in ("%%~tf") do set /a Y2=120%%c-10000&set /a M2=1%%a-100&set /a D2=1%%b-100

    )

    REM convert the data into julian days

    call:date2jdate JD2 Y2 M2 D2

    rem echo JD2 is !JD2!; Y2 is !Y2!; M2 is !M2!; D2 is !D2!

    REM calculate the difference: today - file date

    set /a d=JD1-JD2

    rem echo d is !d!; DAYSOLD is %DAYSOLD%

    if !d! GTR %DAYSOLD% (

    REM format the output

    REM call:jdate2date JD2 YYYY MM DD

    REM set MM=00!MM!&set MM=!MM:~-2!

    REM set DD=00!DD!&set DD=!DD:~-2!

    REM echo.!YYYY!!MM!!DD! !d! days old - %%~nxf

    echo Deleting file %%~f - !d! days old >> dellogs.txt

    del /f "%%~f"

    ) else (

    REM echo Leaving file %%~f - !d! days old

    )

    )

    rem ECHO.&PAUSE&

    GOTO:EOF





    ::-----------------------------------------------------------------------------------

    ::-- Functions start below here

    ::-----------------------------------------------------------------------------------





    :date2jdate JD YYYY MM DD -- converts a gregorian calender date into julian day format

    :: -- JD : out - julian days

    :: -- YYYY: in - gregorian year, i.e. 2006

    :: -- MM : in - gregorian month, i.e. 12 for december

    :: -- DD : in - gregorian day, i.e. 31

    :: -- reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html

    SETLOCAL ENABLEDELAYEDEXPANSION

    set YYYY=%~2

    set MM=%~3

    set DD=%~4

    set /a I=%YYYY%

    set /a J=%MM%

    set /a K=%DD%

    set /a JD=K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12)/12-3*((I+4900+(J-14)/12)/100)/4

    ( ENDLOCAL & REM RETURN VALUES

    IF "%~1" NEQ "" SET %~1=%JD%

    )

    GOTO:EOF





    :jdate2date JD YYYY MM DD -- converts julian days into gregorian date format

    :: -- JD : in - julian days

    :: -- YYYY: out - gregorian year, i.e. 2006

    :: -- MM : out - gregorian month, i.e. 12 for december

    :: -- DD : out - gregorian day, i.e. 31

    :: -- reference http://aa.usno.navy.mil/faq/docs/JD_Formula.html

    SETLOCAL ENABLEDELAYEDEXPANSION

    set /a L= %~1+68569

    set /a N= 4*L/146097

    set /a L= L-(146097*N+3)/4

    set /a I= 4000*(L+1)/1461001

    set /a L= L-1461*I/4+31

    set /a J= 80*L/2447

    set /a K= L-2447*J/80

    set /a L= J/11

    set /a J= J+2-12*L

    set /a I= 100*(N-49)+I+L

    set /a YYYY= I

    set /a MM= J

    set /a DD= K

    ( ENDLOCAL & REM RETURN VALUES

    IF "%~2" NEQ "" SET %~2=%YYYY%

    IF "%~3" NEQ "" SET %~3=%MM%

    IF "%~4" NEQ "" SET %~4=%DD%

    )

    GOTO:EOF


    -----Original Message-----
    From: oracle-l-bounce_at_freelists.org
    On Behalf Of Greg Norris
    Sent: Friday, July 21, 2006 11:13 AM
    To: ORACLE-L
    Subject: Re: batch file scripting >
    On 7/19/06, Steve Perry wrote:
    > >
    that only takes 2 lines :)))
    > >
    C:\>set f=myfile_%date:~10,4%-%date:~4,2%-%date:~7,2%
    C:\>echo %f%
    myfile_2006-07-19
    >
    On a semi-related note, is there any way (using "pure" cmd.exe) to
    identify files older than say, 5 days? For example, something similar
    to "find . -name "myfile\* -mtime +5". >
    Unfortunately I'm not allowed to add additional software, so the use
    of add-on tools like cygwin/perl/etc. simply isn't an option. :( >
    --
    "I'm too sexy for my code." - Awk Sed Fred.
    --
    http://www.freelists.org/webpage/oracle-l
    >
  • Yechiel Adar at Jul 24, 2006 at 5:00 pm
    Very nice script but I use robocopy.exe program (downloaded from the net).
    I have a database that the user claimed that someone was deleting records.
    I put the database in archive log and had to clean the old logs.
    I created a directory named old and did:
    robocopy d:\archive d:\old *.arc /mov /minage:2
    This moved (no extra space required and is done very fast) files that
    are older then 2 days with extension arc from directory archive to
    directory old.
    Then I just did:
    del d:\old\*.*

    Why recreate what is already done?

    Adar Yechiel
    Rechovot, Israel

    Sweetser, Joe wrote:
    -----Original Message-----
    From: Sweetser, Joe
    Sent: Fri 7/21/2006 10:27 AM
    To: spikey.mcmarbles_at_gmail.com; ORACLE-L
    Subject: RE: batch file scripting


    Usage: <# days to delete files older than (?)> :-)





    --
    http://www.freelists.org/webpage/oracle-l
  • Mladen Gogala at Jul 25, 2006 at 2:46 am

    On 07/24/2006 01:00:31 PM, Yechiel Adar wrote:
    Very nice script but I use robocopy.exe program
    I prefer cygwin. It contains "find", "perl", "awk" and "sed".
    There are very few things that cannot be done by using cygwin.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouporacle-l @
categoriesoracle
postedJul 19, '06 at 5:08p
activeJul 25, '06 at 2:46a
posts17
users13
websiteoracle.com

People

Translate

site design / logo © 2022 Grokbase