Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
The issue I am having is part of a validation problem. My script will validate 3 or 4 parameters entered by the user
the first 3 are mandatory the 4th one is not.
After validating that the parameters entered are Ok, it should then (This part being the problem) check to see if the 3 parameters are already within the file that will be modified, to avoid duplicate entries. if the 3 parameters are found inside, than it will replace those with what was entered. I preferred to use grep to remove them out of the file rather than sed, because it doesn't matter which order the entries are in, so appending to the end of the file works fine. *Also within the file it should also not care about the spaces between the entries since it is kind of random, so ignoring the white spaces would be needed.
variables:
domain=$1
type=$2
item=$3
value=$4
This is for school work, so I'd appreciate all help but I would like to understand about it, if an answer is given and that poster could kindly give me some feedback on what I was doing wrong, I will also be researching up on the input I get from you guys, I am not just looking for an easy way out.
- Relevant commands, code, scripts, algorithms:
egrep, modifying limits.conf from the "~/etc/security" directory.
searching for the string within the file.
- The attempts at a solution (include all code and scripts):
input= egrep -e '$domain\s+$type\s+$item' ~/etc/security/limits.conf
if [ "$input" == "" ]; then
echo $domain $type $item $value >>~/etc/security/limits.conf
echo \"$domain\" \"$type\" \"$item\" \"$value\" has been successfully added to your limits.conf file.
else
cat ~/etc/security/limits.conf | egrep -v "$domain|$type|$item" >~/etc/security/limits.conf1
rm -rf ~/etc/security/limits.conf
mv ~/etc/security/limits.conf1 ~/etc/security/limits.conf
echo $domain $type $item $value >>~/etc/security/limits.conf
echo \"$domain\" \"$type\" \"$item\" \"$value\" has been successfully added to your limits.conf file.
exit 0
fi
The red text is where I'm having trouble with.
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Seneca School of Information and Technology, college.
Toronto, ON - Canada
Professor: John Selmys
OPS435
scs.senecac.on.ca/course/ops435
Thank you for any helps and suggestions/feedback
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).