[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] Automated commands



At 3/30/01 04:32 PM +0100, you wrote:
     This may sound a bit stupid but I am looking for a way to automate
certain functions I do. Its kinda like a batch file on a windows system it
just saves me typing stuff in over and over again.

Dom's right: there are no stupid questions. You, I, and everybody else should make every effort to learn more and cure ignorance... even though sometimes it may make us look slightly silly as we transition between two states (such as DOS user and Linux user). I had to grin at this... you *are* just starting out... but I'm glad you asked. Don't lose the habit.

What you want is called a "shell script" for the complicated reason that it is a script run by the shell (the thing that gives you a command prompt and interprets your commands). Most scripts you'll see are run in bash (the Bourne-Again SHell), since pretty much every Linux/Unix system under the sun has that. Highly probable that this is what you use as well.

Note: Also probable that this is what root uses, and the root shellscripts *are* written in bash, so changing root's shell might make your life a little uncomfortable. I don't know... I don't want to try. :)

There have been a couple of good threads on this (I know, I started two). Search for "Shell Scripting" (with or without the caps), and there was a thread about two months ago (about six messages) where several people recommended some good links to me. Of course, one of the suggestions was to work my way through the man pages for bash; run

man bash

to see those. Another was a good bash tutorial on the Web; don't have it to hand right now but ask me if you need the link and I'll post it or mail it to you. Everybody's given you good answers, so my only concrete comments are:

* The very first characters of the file should be      #!/bin/sh
  This tells the system that it is a bash script.
  I didn't include any quotes to avoid confusion.
  First line, first characters, no spaces.

* Insert a list of commands to be executed. The shell keeps an
  environment around, so you can play with variables and such
  to do far more sophisticated things. There are also if, case,
  while, for, and other control structures as well as tests
  and many other things to make your scripts more powerful.
  Study the bash man page... it'll be worth your time.

* When you're done editing, running the command will       chmod 700 script
  give you read, write, and execute permissions but
  leave everyone else not even being able to read it.
  If you're OK with other users running it but not
  reading or writing, use 711. If they can read it
  too, use 755. Don't let them write to it.

* Don't run your scripts as root unless they need to
  be owned by root. In that case, create them as root
  and forbid all others from running them. This will
  save you from a fried system someday.


--
Rodolfo J. Paiz
rpaiz@xxxxxxxxxxxxxx