What's a script?

Rashkae ubuntu at tigershaunt.com
Sun Jul 12 23:01:02 UTC 2009


Mark C. Miller wrote:
> I'm a newbie and know nothing about programming.  Here's a line I grabbed 
> from another thread
> 
> quote
> 
> Basically, stick your ssh commands in a script. Stick the script in the
> appropriate start up file.
> 
> unquote
> 
> What does the author mean by a "script"?  Is this a particular 
> programming language?  Once you get it written, whatever you write it in, 
> what would be the command to execute it, once I figured out what the 
> "appropriate start up file" is?
> 
> Sorry to be so basic, but right now if it doesn't have an interface, I 
> know little about it.  I'd like to change that.
> 
> tnx
> 
> mcm
> 

A script is a series of commands that are executed by the computer.
There are several programming that are considered scripting languages,
such as Perl and Python,  however, in this case, what was likely meant
was to use a shell script.  (A shell is what you call the command
prompt.  The same commands you type at at a command prompt can also be
put into a script, along with other glue language, like conditions (if x
then y) or loops (Repeat x)

You writhe a script by putting your commands in a text file.  You can
create it with any text editor, such as gedit.

The first line of a script should start  with #!/bin/sh

The /bin/sh tells the computer what program will actually be executing
the commands.  In this case, /bin/sh, which should be POSIX compliant
command shell interpreter.  You might also sometimes see #!/bin/bash,
which would do the same thing, but in the case of Ubuntu, bash can
accept some more complicated scripting commands than sh.


The following lines should be the commands you to execute.  Since this
is a shell script, any of the commands you would normally type at the
command prompt will work.

When your script is done, you have to give the file executable
permission, so the system knows that it's meant to be a command.  From
the command line, you can issue the command chmod u+x myscript (where
myscript is the name of the file you just created) to make the file
executable.

Now you can run the script by calling it's file name in a command
prompt.  Note that unless the file gets placed in special system
directories (called PATH), you have to type the complete location of the
file to execute it.

ex:  /home/username/myscript

And finally, run the script from a start-up file, the appropriate
start-up file depends on when exactly you expect the script to be run.
For example, for the script to run as a system (root user) process after
the computer has started, but without requiring a user to log in, you
would use the /etc/rc.local file.





More information about the ubuntu-users mailing list