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

Re: shell scripting



> I want to write a little shell script called "addmailuser" w/c
> executes "adduser --conf /etc/mailuser.conf" where mailuser.conf
> contains info like making their default shell /bin/false.  in dos,
> that "addmailuser" file will simply contain "adduser --conf
> /etc/mailuser.conf %1" where %1 is the first parameter that it sees,
> that is, the name of the user i want to add ... but how do u do this
> in linux ???
> hope someone can guide me on this,

The simplest script in unix would be

------------------------------------------------------------------------
#! /bin/sh

adduser --conf /etc/mailuser.conf $1
------------------------------------------------------------------------

The first line indicates you are running a bourne shell script, which is
the most portable type of script.  The $1 is the first argument.  After
you save the script, you should make it executable:

chmod +x addmailuser

Then as root, you would run it like

./addmailuser joe

to add user joe (root does not have the current directory in its path).
Traditionally, most unix commands can take any number of arguments to do
the same thing with.  A script that could add more than one user in one
run would look like:

------------------------------------------------------------------------
#! /bin/sh

for u in $*; do
  adduser --conf /etc/mailuser.conf $u
done
------------------------------------------------------------------------

Now you can type

./addmailuser bill hilary chelsea

HTH,
Eric

-- 
 E.L. Meijer (tgakem@chem.tue.nl)          | tel. office +31 40 2472189
 Eindhoven Univ. of Technology             | tel. lab.   +31 40 2475032
 Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax    +31 40 2455054


Reply to: