Mysql quary grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mysql quary grep
# 1  
Old 12-05-2016
Power Mysql quary grep

Hi,

im making a script to check replication which works.
my issue is that i want that in the order that i wort the grep search args
the output will be in the same order :

Code:
mysql -e "show slave status\G" | grep "Seconde_behinde_master\|connection_name"

then the output will be :
Code:
connection_name:test
Seconde_behinde_master:378349

instead of going by the order of the search args:
Code:
Seconde_behinde_master:378349
connection_name:test

i know it does it cause it depends on what the grep catches by lines order - but i want the output by search order as im using arrays and it will mess everything up if i have different servers.
can someone help ?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-05-2016 at 09:18 AM.. Reason: Added CODE tags.
# 2  
Old 12-05-2016
The two (or more) regexes joined in an alternation (by the | operator) are equivalent so there is no "search order".
You need to use one grep command for either match, i.e. two for above case, or a totally different approach at all (e.g. an awk script).
# 3  
Old 12-07-2016
OK,
so eventually we user dictionary option instead of array so now
the order doesn't matter as it calls the values by its name and not position.

Code:
function dick_tracy() {
        DIC[$1]=$2
}


function check () {
	declare -A DIC
	while read line
	        do
	        for i in $line
	                do
	                dick_tracy $(echo $i |sed 's/:/ /')
	                done

and we could use -
Code:
${DIC[Seconds_Behind_Master]}

i hope it will help others Smilie
Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) when displaying full line and multi-line sample input, sample output, and code segments.

Last edited by Don Cragun; 12-07-2016 at 02:57 AM.. Reason: Change ICODE tags to CODE tags again.
# 4  
Old 12-07-2016
Perhaps a slight crude suggestion:-
Code:
mysql -e "show slave status\G" | grep "Seconde_behinde_master\|connection_name" | sort -r

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

3. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

4. Red Hat

MySQL conflicts with mysql-3.23.58-16.RHEL3.1

I am tring to install mysql 5.0 on redhat linux3. In this server mysql 3 is already installed and hence while I install mysql 5 it gives the following error. How I can install mysql 5 with out affect previous installation? bash-2.05b# rpm -i MySQL-server-community-5.0.41-0.rhel3.i386.rpm... (2 Replies)
Discussion started by: johnveslin
2 Replies

5. UNIX for Advanced & Expert Users

mysql would not start: missing mysql.sock

I recently installed mysql-standard-5.0.21-solaris9-sparc-64bit.pkg on a Solaris 9 machine (SunOS 5.9 Generic_118558-19 sun4u sparc SUNW,Ultra-250). The package installation went very smooth, however, starting mysql is a different story. I get the message below everytime I try to start mysql: #... (2 Replies)
Discussion started by: xnightcrawl
2 Replies

6. UNIX for Advanced & Expert Users

MySQL problem >> missing mysql.sock

MySQL on my server is down.... I figured out that the mysqld process isn't running. When I try to run it, it says it can't find mysql.sock Any suggestions? Here's what I can't do: can't be root don't have physical access (do stuff via SSH) reinstall MySQL (need to keep the current MySQL... (8 Replies)
Discussion started by: _hp_
8 Replies
Login or Register to Ask a Question