Results 1 to 1 of 1
I'm trying to write a script that will cycle through positional parameters and send a mail to each with a few personalized variables (like the sender's name, and addressing it ...
- 03-25-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 3
mail script using positional parameters
I'm trying to write a script that will cycle through positional parameters and send a mail to each with a few personalized variables (like the sender's name, and addressing it to them personally by retrieving their name from /etc/passwd) This IS homework. I've got four of these to do, and two are giving me trouble, so you may see my other post for the same class.
I'm just getting the end of file unexpected error, but I can't figure out what it is missing. I've tried to step through the code and it seems to work until the actual mail statement, which I really can't figure out because I thought that part was solid when I wrote it. Hrnk.
Below is my attempt. Thanks in advance if anyone decides to help.
#!/bin/sh
if [ $# -eq 0 ]
then
echo "No users listed." >&2
exit 1;
else
until [ -z "$1" ]
do
set loginName="$1"
[ `grep $loginName /etc/passwd | cut -d: -f1` = $loginName ]
know="$?"
if [ $know = 0 ]
then
[ `who | cut -d" " -f 1 | grep $loginName` = $loginName ]
set loggedIn="$?"
if [ $loggedIn = 0 ]
then
mail $loginName << end_of_msg
Hello `grep $loginName /etc/passwd | cut -d: -f 5`
Please ignore this mail. My instructor requires that I
send this message as part of an assignment for class
93.312. The current time and date are `date`.
Have a nice day.
`grep $USER /etc/passwd | cut -d: -f 5`
end_of_msg
shift
else
echo "User not currently logged on." >&2
shift
fi
else
echo "PLEASE ONLY SEND THIS MESSAGE TO USERS WHICH YOU KNOW
PERSONALLY." >&2
fi
done
fi
exit 0;


Reply With Quote