Bourn shell scripts

Bourn shell scripts

Post by Mary Winsto » Fri, 18 Apr 1997 04:00:00



I need to write a Bourne shell script that will accept user id from the
command line and either "write" to the user or send "mail" to the user.
 the script will determine if the user is a valid user. if not, output an
error message.  If the user is logged-in, then "write" to the user. if the
user is not logged-in, then send "mail" to the user.

 
 
 

Bourn shell scripts

Post by Kurt J. Lanz » Fri, 18 Apr 1997 04:00:00



> I need to write a Bourne shell script that will accept user id from the
> command line and either "write" to the user or send "mail" to the user.
>  the script will determine if the user is a valid user. if not, output an
> error message.  If the user is logged-in, then "write" to the user. if the
> user is not logged-in, then send "mail" to the user.

That's nice. Your question was?
--
Kurt J. Lanza


 
 
 

Bourn shell scripts

Post by Chad Wolfsheim » Fri, 18 Apr 1997 04:00:00


: I need to write a Bourne shell script that will accept user id from the
: command line and either "write" to the user or send "mail" to the user.
:  the script will determine if the user is a valid user. if not, output an
: error message.  If the user is logged-in, then "write" to the user. if the
: user is not logged-in, then send "mail" to the user.
Good, so write it! Oh, maybe you want a few suggestions?
To check for a valid username,
        grep ^${1}: /etc/passwd
where the argument to the program is the username desired (i.e. if you call
the program calluser, then the program should be invoked with
        calluser lmnyf
($1 is the first argument to a shell script).

grep the "w" or "ps" listings to find out if the user is logged in (this can
be done the same way:
        w |grep "^$1 "
(Note, the caret specifies beginning of the line)       or
        ps |grep "^$1 "
You will need the quotes to indicate that there should be no more characters
after the username, for the case that there is a user lmnyfg, for example.

If the user is root (who shouldn't be logged in directly, anyway), then
manipulation of the ps entry will be more difficult.

After determining whether the user is logged in (the greps will be empty if
it did not find the user/the user is not logged in), write or mail the user.

Disclaimer: I didn't test these commands, but they should work.

  //===============Chad Wolfsheimer=======Brown University===============\\
 //===================UNIX System/Network Administration==================\\

  \\==============http://bootp-244.diman.brown.edu/~cwolfshe=============//

 
 
 

Bourn shell scripts

Post by Carl R. Whit » Thu, 24 Apr 1997 04:00:00



Quote:> I need to write a Bourne shell script that will accept user id from the
> command line and either "write" to the user or send "mail" to the user.
>  the script will determine if the user is a valid user. if not, output an
> error message.  If the user is logged-in, then "write" to the user. if the
> user is not logged-in, then send "mail" to the user.

I wrote something similar in Korn Shell a while ago, but it's currently in
storage with a bug I can't be bothered to fix...

If you want it, I'll send you a copy... Mail me.

Cheers,
Carl

--


                | web......: http://www.student.comp.brad.ac.uk/~crwhite

 
 
 

1. How to Read Entire Lines from File in Bourn Shell Scripts

        Is there a way in bash or similar shells to cause the shell to read
whole lines from files and assign the string to a variable somewhat like
what one gets if inclosing a string in quotes?

        If you write a loop of the following structure:

     for line_var in `cat stringfile`; do
echo "All of this is static except for $line_var"
done

        What actually happens is that the shell passes each field of each
line in the file to $line_var and the loop runs once for each field in the
file, not each line.

        There are times when one would like to do that, but also times in
which each string in a file should be handled as a single block of data.

        One crude way I got around this the last time I wanted to use whole
lines in a loop was to temporarily replace all the white space with some
printable character that doesn't already appear.  
This effectively makes each line one "word" and then gives me what I
wanted in the beginning but it seems really clunky.

        One then has to exchange all the special characters that stood for
spaces with spaces again to put the file back to its original form.

        Is there a better way to do this in shell script or is it necessary
to use perl or C?

        I certainly don't mind doing that, but bash or Bourn shell scripts
are so great for those little jobs that you may do once every year or so
and don't really call for a tremendous effort if a shell script will do.
Thank you very much for any good ideas.  The UNIX FAQ did not appear to
answer this question, at least not directly enough for me to notice.:-)
--

Martin McCormick WB5AGZ  Stillwater, OK
OSU Center for Computing and Information Services Network Operations Group

2. Strange "df" output on Solaris 9

3. Bourn Shell Scripts

4. powerchute

5. exit status in Bourn shell scripts

6. Apache under NT....

7. passing argument between Bourn shell and Perl script

8. install error: cdrom not recognized

9. Bourn shell

10. control PS1 on the bourn shell

11. Environments, bourn-shells, and dots

12. dose a root only use a bourn-shell?

13. Bourn Shell variables--how to test for "numeric type"??