Results 1 to 9 of 9
I think I have the basic logic down, but I can't get the syntax right for the bash shell. It needs to read the /etc/passwd file and send an e-mail ...
- 05-29-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 26
syntax errors...please help me...
I think I have the basic logic down, but I can't get the syntax right for the bash shell. It needs to read the /etc/passwd file and send an e-mail to all users not currently using a password.
#!/bin/bash
#Checking for file existence
if test -f /etc/passwd ; then
echo "The passwd file was found!"
else
echo "The passwd file could not be found!?"
exit
fi
# display only lines with /bin/bash
USRS=`cat /etc/passwd | egrep "/bin/bash" | awk -F: '$2 != "x" {print $1}'`
echo ${USRS}
USRS=${USRS}" X"
EMAILMESSAGE="Your account does not have a password. Please create one immediately using the passwd command."
SUBJECT="No Password"
i=`expr 1`
while [ 1 ]
do
USR=`awk {print $($i)} ${USRS}`
if [${USR} = "X"] ; then
exit
else
USR=${USR}"@mydomain.com"
/bin/mail -s "${SUBJECT}" "${USR}" < $EMAILMESSAGE
fi
i=`expr $i + 1`
done
- 05-29-2007 #2
What does the syntax error say? What line is it occurring on?
A quick look over the script doesn't show me anything obvious, but until I know what I'm looking for, I'm not going to do anything more.DISTRO=Arch
Registered Linux User #388732
- 05-30-2007 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 05-30-2007 #4Just Joined!
- Join Date
- May 2007
- Posts
- 26
Thanks that helps!
Sorry about not posting the error, I've never really used forums before. Here's the error I'm getting:
"Who are you?: Permission denied"... and then it loops forever.
I'll try the for loop and the incrementation, that's definitely what I've been looking for.
Thanks again
- 05-30-2007 #5
I don't recognize the error, but it sounds like the call to 'mail' might be throwing it. Are you sure that you're invoking it correctly?
DISTRO=Arch
Registered Linux User #388732
- 06-01-2007 #6Just Joined!
- Join Date
- May 2007
- Posts
- 26
No I'm not sure...
I'm very new to linux. I open up man pages and they still look a lot like a wall of text. Could you recommend some ways to do so...invoke mail that is?
- 06-02-2007 #7
Out of curiosity, is the e-mail being sent anyway? One of the few references I can find online mentions that he gets this error, but the e-mail is still sent.
Also, what are the permissions on your /etc/passwd file? You can determine this by running the command:
Code:ls -l /etc/passwd
DISTRO=Arch
Registered Linux User #388732
- 06-02-2007 #8Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Excerpt from original script:
I would change the if to use required spaces around the square brackets:Code:if [${USR} = "X"] ; then exit else USR=${USR}"@mydomain.com" /bin/mail -s "${SUBJECT}" "${USR}" < $EMAILMESSAGE
and the mail line will attempt to read the mail message from a file named:Code:if [ ${USR} = "X" ] ; then
because you are requesting to read from a file name rather than using the text of the variable. You can make an easy change by using a here document. I know this can be confusing when you are learning scripting.Code:Your account does not have a password. Please ...
One way to make this work is to use a test -- use cat instead of /bin/mail:
If you can see the message, then replace the cat with /bin/mail and other parameters, but be sure to keep the here document.Code:cat <<EOF $EMAILMESSAGE EOF
Also as a test, arrange to send the email to yourself, so that you can see if things are working correctly. When you start getting the email, then you can start using the other addresses.
Please try to get in the habit of using CODE tags, it will make it easier for responders to help you -- select the text and then click the # button just above the editing window,
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 06-02-2007 #9Just Joined!
- Join Date
- May 2007
- Posts
- 26
Thank You!
I was able to get it working, and I was making it overly complicated. Thank you for the help with the syntax, that was one of the major issues. Also, the e-mails were getting sent. The error was about a user that could sign in, but the system didn't recognize them as having a user name... I don't really get that, but I fixed it. All is well and thanks to everyones help


Reply With Quote
