Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Issues with Simply Bash Script

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
zgould
Posts: 1
Joined: 2015-08-04 20:25

Issues with Simply Bash Script

#1 Post by zgould »

I'm new to Bash scripting, and I'm simply trying to make a "E-mail creation" script that will check to see if there is already an e-mail in the file, and if so it gives you a error. If not, it adds the e-mail. I can't get it to work, any ideas?

The script either keeps adding the same e-mail over without erroring out, or I've made it error out, but it matches the entire string (Meaning it doesn't differentiate between zgould@hank.com, or zgould@cheese.com, it errors on both)

Thank you!

#!/bin/bash
FILE=/etc/postfix/sender_dependent_relayhost
echo "Please Enter Username:"
read Username
sleep 2
echo "Please Enter Domain (Include @):"
read Domain
sleep 2
email=$Username$Domain
#########

cmd=$(grep -Fxq "$email" $FILE)

if [ "$email" == "$(cat $FILE)" ];
then
echo "Already Exists"
else
echo -e "$email \t mci02-mailenc001.arsalonmessaging.net:25" >> /etc/postfix/sender_dependent_relayhost

echo

########
echo "E-mail $email has been added"
sleep 1
echo
#######
/root/mailconf/reload-postfix.sh
echo
echo -e "E-mail has been added. Be Well"
fi
~

User avatar
dasein
Posts: 7680
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Issues with Simply Bash Script

#2 Post by dasein »

I'm not 100% convinced that this isn't a homework problem, so pardon me if I don't do more than point you in the right direction...

My entirely rhetorical question to you is: what's that grep doing in there? (To be clear, I'm not saying that it does--or doesn't--belong in there; I'm suggesting that once/if you figure out what the grep is doing, you'll be one step closer to seeing the underlying problem.)

User avatar
GarryRicketson
Posts: 5644
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Issues with Simply Bash Script

#3 Post by GarryRicketson »

Code: Select all

man grep 
might help, in understanding what the grep command does.

Post Reply