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
~
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
Re: Issues with Simply Bash Script
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.)
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.)
- GarryRicketson
- Posts: 5644
- Joined: 2015-01-20 22:16
- Location: Durango, Mexico
Re: Issues with Simply Bash Script
Code: Select all
man grep
"What we expect you have already Done"
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?
==========
Old Website
======================
For the Birds
==================
What Does a Parrot Know About PTSD?