From 4739e8b7cb8abe402a5b724de3e19d0d63868ff7 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 4 Feb 2017 22:51:32 +0000 Subject: [PATCH] etc/profile.d/sys.sh --- bin/ovh-api | 30 +++++++++++++++++++++++++++++- etc/profile.d/sys.sh | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/bin/ovh-api b/bin/ovh-api index febf94bb..92b46f73 100755 --- a/bin/ovh-api +++ b/bin/ovh-api @@ -118,7 +118,8 @@ sub query { print "[\n" if @$content>0; my $count = 0; for my $id (@$content) { - next if $URL eq '/ip' and $id !~ /\d+\./; + $id = check_row($URL,$id); + next unless defined $id; $id =~ s,/.*$,,; $response = $Api->rawCall(path=>$URL.'/'.$id,method=>$Opt{method},body=>{}); @@ -138,6 +139,32 @@ sub query { print "$content\n"; } +sub sql { +my $pref = 'ovh_'; +my @tables = ( + { + name => 'ip', + url => '/ip', + sql => 'CREATE TABLE IF NOT EXISTS '.$pref.'ip (' + .');', + }, + { + name => 'server', + url => '/server', + sql => 'CREATE TABLE IF NOT EXISTS '.$pref.'server (' + .'serverid INT,' + .');', + }, +); +} + +sub check_row { + my ($URL,$id) = @_; + return undef if $URL eq '/ip' and $id !~ /\d+\./; + $id =~ s,/.*$,,; + return $id; +} + sub help { #------------------------------------------------------------------------------ # Print help and exit @@ -234,6 +261,7 @@ $NAME - Script to query ovh's api 4. Use the api $NAME applicationKey:applicationSecret:consumerKey /PATH $NAME /PATH + $NAME --rows /PATH =head1 OPTIONS diff --git a/etc/profile.d/sys.sh b/etc/profile.d/sys.sh index 647a51cb..43b8e8a6 100644 --- a/etc/profile.d/sys.sh +++ b/etc/profile.d/sys.sh @@ -11,6 +11,7 @@ sys_watch() { local opt="$@" [ -z "$opt" ] && opt="-d" + export -f sys_activity watch --no-title $opt bash -c "sys_activity" } -- 2.47.3