scripting doubts
Arthur Meeks Meeks
arthur.meeks.luppu at gmail.com
Wed Aug 5 07:52:39 UTC 2009
2009/8/5 Cameron Simpson <cs at zip.com.au>
> On 04Aug2009 20:04, Arthur Meeks Meeks <arthur.meeks.luppu at gmail.com>
> wrote:
> | I'm doing an "egrep "REPLICATION CLIENT|ALL" | wc -l" after the mysql
> | -pwhatever -e "show grants for...etc" all this is redirected to a file
> using
> | normal ">".
> | So:
> | for i in `cat file` do mysql -p -e "show grants etc.." "egrep
> "REPLICATION
> | CLIENT|ALL" | wc -l > /tmp/whatever basically.
> |
> | /tmp/whatever has the following "format":
> | server1:0
> | server2:1
> | server3:0
> | etc
> |
> | I use another "for" to read this file and decide whether the database has
> | the right privileges, if it has REPLICATION CLIENT or ALL privileges, "wc
> | -l" will return 1 or more than 1, if it doesn't have any of them it will
> be
> | a 0.
> |
> | What's the problem? When I can't log into a mysql database (mostly cause
> it
> | is down) I got a "0", what I want is to discard these machines, so
> they're
> | not included in /tmp/whatever.
> | I tried doing: grep -v "ERROR" and doing a 2> /dev/null after the mysql
> -p
> | -e "show grants etc.." but it doesn't work.
>
>
> You're probably not getting to pay attention to the mysql exit status.
> Perhaps something line this:
>
> : ${TMPDIR:=/tmp}
> cmd=`basename "$0"`
> tmpbase=$TMPDIR/$cmd.$$
> trap 'rm -f "$tmpbase".*' 0 1 3 15 # tidy up
>
> grants=$tmpbase.grants.txt
> while read host
> do
> mysql -h "$host" -ublah -pfhfhfhfhf -e "show grants..." >"$grants" \
> || { echo "skipping $host, maybe down" >&2
> continue
> }
> egrep ......... <"$grants" | wc -l ...
> done < file-of-hosts
>
> Cheers,
Hi Cameron,
First off, thanks a lot.
I've been trying to include those lines in my script without modifying it
too much but it wasn't possible.
How would you include your piece of code to this script:
#!/bin/bash
PASS="fff"
LIST="/tmp/perms"
for i in `cat /opt/lists/*clusters`; do echo -n $i: && mysql -h$i -uroot
-p$PASS -e"show grants for 'user'@'10.10.%.%';" | egrep "REPLICATION
CLIENT|ALL" | wc -l ; done > $LIST
if [ -e $LIST ]
then
for i in `cat $LIST`
do
d="`echo $i | awk -F ":" '{ print $1 }'`"
perms="`echo $i | awk -F ":" '{print $2 }'`"
if [ $perms = 0 ]
then
echo "machine $d has not the correct perms please check them out
with: show grants for user 'user'@'10.10.%.%'" | mail -s "Incorrect MySQL
privileges in $d" user at domain.com
fi
done
fi
Thanks
A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.fedoraproject.org/pipermail/users/attachments/20090805/4be6fc63/attachment-0001.html
More information about the users
mailing list