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. <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>
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?
<SNIP> A windows BAT file is a rudimentary subset of a shell script. I don't know if there are any linux utilities to execute a windows bat file but the first thing I'd do is to learn the bash shell and rewrite the BAT file into a bash shell script. There's megatons of information on the web on how to write bash (or C, Bourne, Korn etc) shell scripts. Bash is the default Linux shell. I use the O'Reilly book "Learning the bash Shell" personally.
* expatriate
file into a bash shell script. There's megatons of information on the web on how to write bash (or C, Bourne, Korn etc) shell scripts. Bash is the default Linux shell. I use the O'Reilly book "Learning the bash Shell" personally.
I can recommend this page: http://shelldorado.com/ I've found tons of useful stuff there. -- Mads Martin Joergensen, http://mmj.dk "Why make things difficult, when it is possible to make them cryptic and totally illogical, with just a little bit more effort?" -- A. P. J.
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 doesn't directly support bat files. I would recommend you do a google for "linux shell scripting" for a quick tutorial on Linux's version of bat files. You'll find the shell scripting language syntax very similar, though not identical, to a batch file and I'm certain you'll be able to accomplish what you need to do with minimal effort. A little bit of reading is all that is required. I'll start you off with a very good shell scripting site: http://steve-parker.org/sh/sh.shtml
On Thu, 2004-04-29 at 09:51, 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.
<begin bat file snippet>
<snip>
<end bat file snippet>
In the *nix world they are called shell scripts and are made executable by their permissions, they require the executable bit be set as in rwxr_xr_x (755). Do a man page on whatever your flavor of shell you use for info on what is available for shell commands. You can always call external programs as well. -- Ken Schneider unix user since 1989 linux user since 1994 SuSE user since 1998 (5.2)
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
On 29 Apr, 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.
<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>
Steve, If this kind of customization is what you expect from your computer, you have come to the right place. With patience, GNU/Linux will likely become your happy home. This said, a little reading and experimentation will yield far greater results here than in a MS Windows environment. While .bat files provide a handy method through which to create quick utilities, particularly for configuration and file management purposes, they are limited in their ability to interact with other programs that virtually require a GUI interface. Not so in an Unix environment, which is essentially all about text files calling on one another - with no need for GUI startups. In fact, most everything runs better behind the scenes. Pontification aside, here's what I recommend. Get some instructional material on Shell, Perl and TK. Knowledge in these areas will allow you to write just about any command line app you require. They're rather intuitive to my mind, and you should be able to learn them quickly. Coming from a windows environment, I think you will find TK of particular use, as it facilitates a series of apps that will help you learn the differences between Windows and Unix methodologies. Also, I strongly urge you to read your existing Shell scripts and configuration files religiously. Even if you don't quite understand them in the beginning, follow their system calls and library loading, etc., as much as you can. Again, Unix/Linux functions through a series of interlaced files (largely text). So if you master the art of reading these files and start to write your own, you will have total control ;) - which is really what we mean by FREE software. I realize this might sound like preaching, but I wish someone had properly explained the need for this information when I started running this very distro some five years ago. I can't tell you how much I struggled trying to make early Yast configure everything for me (what a mangled mess I would weave in those early days). Welcome and cheers!! Regards, -- John Lalla Santa Barbara, CA .~. _ /v\ -o) no gates... /( )\ /\\ running GNU/Linux no windows! ^^^^^ _\_v free at last! "Our capacity for understanding is inversely proportional to how much we think we know. The more I know, the more I know I don't know . . . "
Thanks All I stepped off into the deep end tonight... After 3 or 4 months of experimenting with various Linux distributions, I decided to move from Windows to (SuSE) Linux as my primary operating system. After making significant changes to my home network, partitions and excel spreadsheets, the one thing that was outstanding was devising a backup procedure to replace my existing windows bat file procedures. Whilst I can't abandon Windows completely (I own an iPod and an unsupported film scanner and printer) it will be an interesting experiment. I'll use your recommendations as the basis for my new backup script. Steve
On Thursday 29 April 2004 11:09 am, Steve Reynolds wrote:
Thanks All
I stepped off into the deep end tonight...
After 3 or 4 months of experimenting with various Linux distributions, I decided to move from Windows to (SuSE) Linux as my primary operating system.
After making significant changes to my home network, partitions and excel spreadsheets, the one thing that was outstanding was devising a backup procedure to replace my existing windows bat file procedures.
Whilst I can't abandon Windows completely (I own an iPod and an unsupported film scanner and printer) it will be an interesting experiment.
I'll use your recommendations as the basis for my new backup script.
Steve
Maybe if you described what you do for a backup procedure, we could help. My first thought was to just use a cron job (scheduled) job to run 'rsync' to synchronize a backup area.... but would need to know what you actually do for backups. It is probably easier to implement than you can imagine... :-) -- +----------------------------------------------------------------------------+ + Bruce S. Marshall bmarsh@bmarsh.com Bellaire, MI 04/29/04 11:54 + +----------------------------------------------------------------------------+ "Sigmund's wife wore Freudian slips."
On Friday 30 April 2004 1:25 am, Bruce Marshall wrote:
Maybe if you described what you do for a backup procedure, we could help.
My first thought was to just use a cron job (scheduled) job to run 'rsync' to synchronize a backup area.... but would need to know what you actually do for backups.
It is probably easier to implement than you can imagine... :-)
My needs are simple, I only have 4 commands: On my main, dual boot machine I have two 60GB disks, one formated for Windows and the second formated for Linux. I have a second older machine on my home network that only has a Linux operating system, it will be principlely used as a backup machine. These three commands sync files on my Windows disk to my Linux disk, they represent files produced for/by my film scanner, iPod and Dreamweaver: rsync -r --delete "/windows/E/Steve/My Pictures" /home/steve rsync -r --delete "/windows/E/Steve/My Music" /home/steve rsync -r --delete "/windows/E/Steve/Web Sites" /home/steve This is the most important command as it syncs/backsup all my data files to the windows disk: rsync -r --delete /home/steve/Documents /windows/E/Steve I will add a fifth command when I can work out how to rsync my data files to the second machine on my home network, but it will look something like: rsync -r --delete /home/steve/Documents 192.168.0.7:home/steve At the moment this command doesn't work because I have some sort of permissions problem that is preventing me from writing to the remote disk.. Steve
On Thursday 29 April 2004 01:03 pm, Steve Reynolds wrote:
On Friday 30 April 2004 1:25 am, Bruce Marshall wrote:
Maybe if you described what you do for a backup procedure, we could help.
My first thought was to just use a cron job (scheduled) job to run 'rsync' to synchronize a backup area.... but would need to know what you actually do for backups.
It is probably easier to implement than you can imagine... :-)
My needs are simple, I only have 4 commands:
On my main, dual boot machine I have two 60GB disks, one formated for Windows and the second formated for Linux. I have a second older machine on my home network that only has a Linux operating system, it will be principlely used as a backup machine.
These three commands sync files on my Windows disk to my Linux disk, they represent files produced for/by my film scanner, iPod and Dreamweaver:
rsync -r --delete "/windows/E/Steve/My Pictures" /home/steve rsync -r --delete "/windows/E/Steve/My Music" /home/steve rsync -r --delete "/windows/E/Steve/Web Sites" /home/steve
This is the most important command as it syncs/backsup all my data files to the windows disk:
rsync -r --delete /home/steve/Documents /windows/E/Steve
I think you should be ending each path with a '/' as in: rsync -r --delete "/windows/E/Steve/Web Sites/" /home/steve/ Let rsync know that you are dealing with directories...
I will add a fifth command when I can work out how to rsync my data files to the second machine on my home network, but it will look something like:
rsync -r --delete /home/steve/Documents 192.168.0.7:home/steve
To go remotely, you either need to have rsync's talking to each other (something I never bothered to learn about) or use ssh. My command for the above would be: rsync -rlptuv -e ssh --delete /home/steve/Documents/ 192.168.0.7:/home/steve/ with a passwordless setup for ssh between the two machines. Get all that working and then just add them to your crontab file.
At the moment this command doesn't work because I have some sort of permissions problem that is preventing me from writing to the remote disk..
Steve
-- +----------------------------------------------------------------------------+ + Bruce S. Marshall bmarsh@bmarsh.com Bellaire, MI 04/29/04 13:17 + +----------------------------------------------------------------------------+ "Let him who takes the Plunge remember to return it by Tuesday."
On Thu, 2004-04-29 at 17:09, Steve Reynolds wrote:
Thanks All
I stepped off into the deep end tonight...
After 3 or 4 months of experimenting with various Linux distributions, I decided to move from Windows to (SuSE) Linux as my primary operating system.
After making significant changes to my home network, partitions and excel spreadsheets, the one thing that was outstanding was devising a backup procedure to replace my existing windows bat file procedures.
Whilst I can't abandon Windows completely (I own an iPod and an unsupported film scanner and printer) it will be an interesting experiment.
I'll use your recommendations as the basis for my new backup script.
Well steve... You are probably going to love, shells, Perl, Tk, Python,etc But... If it's a backup you want... have you looked into storebackup? Comes on SuSE cd's and is the ultimate backup program (assuming you backup to disk) Jerry
Steve
On Friday 30 April 2004 2:00 am, Jerome R. Westrick wrote:
If it's a backup you want... have you looked into storebackup? Comes on SuSE cd's and is the ultimate backup program (assuming you backup to disk)
No... I'd never heard off it. I've just downloaded it using YaST and will check it out tomorrow. (It's 3am here at the moment -- time fly's when you're having fun!!) Thanks for the heads-up. Steve
On Thu, 2004-04-29 at 15:51, 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?
Same Bat time, Same Bat Channel, Same Bat files.... Seriously, now... you do thoose in a "shell". Unlike windows, there are lots of them around. Additinally, you can program the commands in one of the many "Interpreters" around (perl, python, ruby) come to mind.... and execute that. I know better than to suggest one over the other, as that is sure to start of a long thread with a bunch of people touting thier faveorites.... hope this helped.... At least so you can make your next question.... Jerry
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.
<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>
participants (9)
-
Bruce Marshall
-
expatriate
-
Jerome R. Westrick
-
John Lalla
-
Kenneth Schneider
-
Mads Martin Joergensen
-
Michael Ferguson
-
Nick LeRoy
-
Steve Reynolds