[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Which tool, and how, to get partial string from file?



Kent West wrote:

Stefan O'Rear wrote:

On Fri, Aug 20, 2004 at 09:46:52PM -0500, Kent West wrote:
How can I test to see if the word "tuber" is in the /etc/passwd file, reliably, and take an action if it is, and take a different action if it's not, in a bash shell script?


if grep -q '\<tuber\>' /etc/passwd
then
echo 'NOOOOOO! THERE ARE POTATOES IN MY PASSWORD! ABORT! ABORT!' | mail root
else
  echo "foo. Foo? passwords are clean..." | mail root
fi


How do I test to make sure the name is in two files? Like so?

if ( ! grep -q '\<tuber\>' /etc/passwd ) or ( ! grep -q '\<tuber\>' /etc/shadow )
then
 echo "Error: One or both files are missing 'tuber'" | mail root
 exit 1
fi

Thanks!

--
Kent



Reply to: