Re: scripting doubts

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

 



On 04Aug2009 20:04, Arthur Meeks Meeks <arthur.meeks.luppu@xxxxxxxxx> 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,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux