From f1f48dee8f211b18297e0033b7462cab5bdb05d7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 3 Mar 2016 10:36:15 +0000 Subject: [PATCH] better ssh --- bin/dbq | 61 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/bin/dbq b/bin/dbq index f7ef7be0..906364fa 100755 --- a/bin/dbq +++ b/bin/dbq @@ -27,10 +27,11 @@ my %ACTION = ( ); my %CMD_ALIASE = ( - 'f' => 'format', + 'd' => 'db', 't' => 'table', - 'a' => 'action', + 'f' => 'format', 'l' => 'limit', + 'a' => 'action', ); ## Vim: r!% --curl_help_hash | grep X @@ -66,49 +67,54 @@ my %Opt = map{ (/^(.*?)\|/ ? $1 : $_) => $CURL_OPT{$_} } keys %CURL_OPT; get_options(\%Opt,\@CURL_OPT); -for my $o (@CURL_OPT) { - $o =~ s/\|.*$//; - next unless $Opt{$o}; - if (ref($Opt{$o}) eq 'ARRAY') { - push(@ARGV,map{ ("--$o",$_) } @{$Opt{$o}}); - - } elsif ($Opt{$o} ne '1') { - push @ARGV,"--$o",$Opt{$o}; - - } else { - push @ARGV,"--$o"; - } -} - ################################################################################# # -# BEGIN +# Build command # ################################################################################# -################################################################################# # -# Build command +# Get URL # -my @cmd; -my $url; -$url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : '/opt/rent/www/index.php'); +my $url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : '/opt/rent/www/index.php'); + if (!$Opt{ssh} and @ARGV and ($ARGV[0] =~ m|^\w+://| or -e $ARGV[0] )) { $url = shift @ARGV; - shift @EXEC; + @EXEC = grep {$_ ne $url} @EXEC; } #die $Opt{ssh}; #exec('ssh',$ARGV[0] && shift @ARGV,$NAME,@ARGV) if @ARGV and $ARGV[0] eq '--ssh' and shift @ARGV; -if ($url =~ m@^ssh://(.*)$@) { - $Opt{ssh} = $1; + +$url =~ s,^(\w+://)?([^@]+)@(.*?)$,$1$3, and push(@EXEC,"db=$2"); + +$url =~ m@^ssh://(.*)$@ and $Opt{ssh} = $1; +#die "$url | ",join(' ',@EXEC); + +exec('ssh',$Opt{ssh},$NAME,map{s/"/\\"/g;'"'.$_.'"'} @EXEC) if $Opt{ssh}; + +# +# Add options to ARGV +# +for my $o (@CURL_OPT) { + $o =~ s/\|.*$//; + next unless $Opt{$o}; + if (ref($Opt{$o}) eq 'ARRAY') { + push(@ARGV,map{ ("--$o",$_) } @{$Opt{$o}}); + + } elsif ($Opt{$o} ne '1') { + push @ARGV,"--$o",$Opt{$o}; + + } else { + push @ARGV,"--$o"; + } } -exec('ssh',$Opt{ssh},$NAME,@EXEC) if $Opt{ssh}; # # Distinct arg from key=value # -push (@cmd,$_) if ($_ = '-'.'v'x($VERBOSE-1) ) ne '-'; my %keys = (); +my @cmd = (); +push (@cmd,$_) if ($_ = '-'.'v'x($VERBOSE-1) ) ne '-'; while ($_ = shift @ARGV) { if (/^([\w\._:-]+)=(.*)$/) { @@ -128,6 +134,7 @@ while (my ($k,$v) = each %ACTION) { } $keys{header} = '0' if $keys{action} ne 'rows'; +$keys{table} = $1 if $keys{db} and $keys{db} =~ s/:(.*)$//; ################################################################################# # -- 2.47.3