Re: [SLE] Bat files in Linux

From: Nick LeRoy (nleroy_at_cs.wisc.edu)
Date: 04/29/04

  • Next message: Prabu Subroto: "[SLE] routing server with SuSE machine (revised)"
    To: suse-linux-e@suse.com
    Date: Thu, 29 Apr 2004 09:07:29 -0500
    
    

    On Thu April 29 2004 8:51 am, Steve Reynolds wrote:
    > I have a few commands that I would like to run at the command prompt.
    >
    > In Windows I do this with a bat file that looks like the sample below. How
    > do I do a similar thing with Linux?
    >
    > For those not familiar with windows bat files the snippet below presents
    > the user with a menu at the command prompt.
    >
    > In windows I have a shortcut to a text file called backup.bat, when I
    > double click that shortcut I launch a DOS window with the menu below
    > already loaded for the user. I would like to do a similar thing with Linux.

    Linux has much more powerful scripting languages. A simple replacement would
    be writing a "shell" script; "man bash" for more details.

    You may be better served, however, with a something like perl, which is an
    extremely powerful scripting language.

    In perl, your script would probably look something like this (quick hack, not
    verified, etc):

    #! /usr/bin/env perl
    use strict;
    use warnings;

    $|=1;
    while( 1 )
    {
        print " Backup Menu";
        print " ===========";
        .....
        print " Q. Quit";

        print "Enter your choice: ";
        <>; chomp;
        if ( /a/ )
        {
             # Do something here...
        }
        elsif ( /b/ )
        {
             # Handle b here...
        }
    }

    Hope this helps. Google for perl; there are a lot of perl resources out
    there.

    -Nick

    > <begin bat file snippet>
    >
    > @ECHO OFF
    > CLS
    >
    > :LOOP
    >
    > ECHO Backup Menu
    > ECHO ===========
    > ECHO A. Flash Drive Backup J:
    > ECHO B. Main Backup to CD
    > ECHO C. Main Backup to F Drive
    > REM ECHO D. Archive Backup
    > ECHO E. Allofmp3 Backup to CD
    > ECHO F. Flash Drive Backup I:
    > REM ECHO G. REVERSE Flash Drive Backup From Linux:
    > ECHO H. Photos Backup to iPod
    > ECHO Q. Quit
    >
    > :: SET /P prompts for input and sets the variable
    > :: to whatever the user types
    >
    > SET Choice=
    >
    > SET /P Choice=Type the letter and press Enter:
    > :: The syntax in the next line extracts the substring
    > :: starting at 0 (the beginning) and 1 character long
    >
    > IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
    > ECHO.
    >
    > :: /I makes the IF comparison case-insensitive
    >
    > IF /I '%Choice%'=='A' GOTO ItemA
    > IF /I '%Choice%'=='B' GOTO ItemB
    > IF /I '%Choice%'=='C' GOTO ItemC
    > IF /I '%Choice%'=='D' GOTO ItemD
    > IF /I '%Choice%'=='E' GOTO ItemE
    > IF /I '%Choice%'=='F' GOTO ItemF
    > IF /I '%Choice%'=='G' GOTO ItemG
    > IF /I '%Choice%'=='H' GOTO ItemH
    > IF /I '%Choice%'=='Q' GOTO End
    > ECHO "%Choice%" is not valid. Please try again.
    > ECHO.
    > GOTO Loop
    >
    > :ItemA
    >
    > <snip>
    >
    > <end bat file snippet>

    -- 
               <<< Why, oh, why, didn't I take the blue pill? >>>
     /`-_    Nicholas R. LeRoy               The Condor Project
    {     }/ http://www.cs.wisc.edu/~nleroy  http://www.cs.wisc.edu/condor
     \    /  nleroy@cs.wisc.edu              The University of Wisconsin
     |_*_|   608-265-5761                    Department of Computer Sciences
    -- 
    Check the headers for your unsubscription address
    For additional commands send e-mail to suse-linux-e-help@suse.com
    Also check the archives at http://lists.suse.com
    Please read the FAQs: suse-linux-e-faq@suse.com
    

  • Next message: Prabu Subroto: "[SLE] routing server with SuSE machine (revised)"

    Relevant Pages

    • Re: Unwanted Paste behavior
      ... But the app ... Usually if I leave Bat/CMD I go to Perl since it is so much easier than ... or at the command prompt. ... What's odd is that Echo. ...
      (microsoft.public.windows.server.general)
    • Re: Help on Perl Scripting
      ... Im trying to convert c shell script to PERL but haven't use PERL ... echo "Create backup directory..." ...
      (comp.lang.perl.misc)
    • Re: "New" ZFS crash on FS (pool?) unmount/export
      ... the box stopped responding to pings at 02:07AM and it has a cron backup job using zfs send/recv at 02:00, so I'm guessing it's related, even though the backup probably should have finished before then... ... Essentially, it creates a GEOM provider of a file, containing a zpool, imports the pool and creates a clone to it, and then exports the pool. ... Every time it crashes it seems to be during or very soon after the export - only this time it didn't even take the snapshots. ... echo Creating ggate device ...
      (freebsd-current)
    • Re: modify incremental_backup
      ... Try the following batch file: ... Run the file from the Command Prompt as it is and check if it ... Remove the word "echo" in line 11 to activate the backup feature. ...
      (microsoft.public.windows.server.scripting)
    • RE: NT Backup inconsistent medium
      ... I would configure the backup with NTBackup and set a schedule from there. ... | directory's to a tape with NT backup it works fine. ... | @ECHO Off ... | REM Script gebaseerd op NT Backup ...
      (microsoft.public.windows.server.sbs)