It is currently Tue, 30 Nov 2021 18:14:43 GMT



 
Author Message
 Im very close but I need a hint on my bourne shell script

Thanks to all of you who answered my first cry for help. Here's my next
one.
I need a bourne script that will accept a user-id from the command-line and
either "write" the user, if he's logged on, or mail the user if he's not.
   This is what I have so far. I know I'm close I just need a little push.

and Bela if you read this how's my indentation now?:)
 Thanks

1  #!/bin/sh
     2  #rap s309
     3  if [ $# = 0 ]
     4  then echo "You must type the name of the person you want to rap
with!"
     5  fi
     6
     7  for i
     8  do
     9   awk -F: '{print $1, $5}' /etc/passwd |
    10     grep $1: /etc/passwd > /dev/null
    11     if [ $? -ne 0 ]
    12   then
    13      echo $1 is not a valid user, try again
    14     fi
    15   who -q | grep $1 > /dev/null
    16    if [ $? -eq 0 ]
    17    then write $1
    18      elif
    19       echo do you want to mail a new message to $1
    20       echo            y or n
    21        read line
    22         case $line in
    23          y|yes) mail $1;;
    24          n|no) ;;
    25         esac
    26       else
    27        echo do you have something prepared to send to $1
    28        echo            y or no
    29         read res
    30          case $res in
    31           y|yes) echo name of file
    32                read name
    33                mail < $name $1;;
    34           n|no) ;;
    35          esac
    36       fi



 Sun, 10 Oct 1999 03:00:00 GMT   
 Im very close but I need a hint on my bourne shell script

Well, your newsgroup selection is still atrocious...

Regarding indentation: if your indentation was doing its job, you
wouldn't be asking for help.  You have a sequence of: if ... then ...
elif ... else.  You're missing a "then" for the "elif".

There are many other things wrong, of course...  Remember not to
continue if the arguments are unacceptable.  Your check for valid user
duplicates itself (only one of grep or awk needs to read /etc/passwd).
Various other minor errors.



 Sun, 10 Oct 1999 03:00:00 GMT   
 Im very close but I need a hint on my bourne shell script

: Thanks to all of you who answered my first cry for help. Here's my next

I don't see why you need anything more than the following:

for uid
do      write $uid || (echo mailing $uid instead...; mail $uid)
done

Remember the KISS principle.

P.S. The thing I notice most about people who cross-post up the wazoo
is that often they end up reposting their question because they get too
lazy to read _all_ the groups where their questions may indeed be answered.

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  
.'  / \  `.'  / mailto:bsh29...@challenger.atc.fhda.edu \  `.'  / \  `.
__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__



 Wed, 13 Oct 1999 03:00:00 GMT   
 
   [ 3 post ] 

Similar Threads

1. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

2. help in learning how to do Bourne shell scripts then converting them to csh scripts


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software