LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2018, 05:13 PM   #1
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Rep: Reputation: Disabled
CRUD by SSH to a Database


Hi, could you give me a little idea of how to do this, I'll tell you.

I'm doing a bash script in which I make a query to the database and the result goes through it with a cycle

something like that:
but since I remotely connect to another computer by ssh and run a local script.

-------------main script---------------------------------------
mysql -u${username} -p${password} -D${database} -n <<<'SELECT row FROM BD.Tbl' 2>/dev/null |
while IFS='\n' read row; do
if [[ ${row} != "row" ]]; then
echo $row

ssh PCB@ x.x.x.x 'bash -s' < script.sh $row
fi
done
-------------------------------------------
the problem I have is the following within the script.sh I get information that I want to store in a database, how could I insert it into this script
so I don't have to make another connection, since I think I could use the same mysql object I have :

PCA - Server

PCB - I get the information and want to save it on the PCA team as I could do it.

the script.sh has the following structure:

#! /usr/bin/env bash

declare -a StrMo=($(free -m | sed -n 1!p |sed -n 1p | sed s/Mem://g));

strOpen="("
strClose=")"

strTotal="${StrMo[@]:0:1}"

strQuery="$strOpen '$strTotal' strClose"

the strQuery variable I want to store in the database.

I'll keep you posted, thank you.

and when I run the main script it gets me the following message:
ssh: Could not resolve hostname : Name or service not known
 
Old 06-27-2018, 06:34 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by m0rt View Post
Hi, could you give me a little idea of how to do this, I'll tell you.

I'm doing a bash script in which I make a query to the database and the result goes through it with a cycle

something like that:
but since I remotely connect to another computer by ssh and run a local script.

-------------main script---------------------------------------
mysql -u${username} -p${password} -D${database} -n <<<'SELECT row FROM BD.Tbl' 2>/dev/null |
while IFS='\n' read row; do
if [[ ${row} != "row" ]]; then
echo $row

ssh PCB@ x.x.x.x 'bash -s' < script.sh $row
fi
done
-------------------------------------------
the problem I have is the following within the script.sh I get information that I want to store in a database, how could I insert it into this script
so I don't have to make another connection, since I think I could use the same mysql object I have :

PCA - Server

PCB - I get the information and want to save it on the PCA team as I could do it.

the script.sh has the following structure:

#! /usr/bin/env bash

declare -a StrMo=($(free -m | sed -n 1!p |sed -n 1p | sed s/Mem://g));

strOpen="("
strClose=")"

strTotal="${StrMo[@]:0:1}"

strQuery="$strOpen '$strTotal' strClose"

the strQuery variable I want to store in the database.

I'll keep you posted, thank you.

and when I run the main script it gets me the following message:
ssh: Could not resolve hostname : Name or service not known
(bold added for emphasis only)
Did you not understand the bolded line? It's telling you specifically that it can't resolve that name in DNS, or the IP address can't be reached. And have you looked at the mysql command or read the man pages? The -H option tells you specifically how to connect to a remote host directly, with no need for an SSH-and-script-run.
 
Old 06-27-2018, 09:58 PM   #3
m0rt
LQ Newbie
 
Registered: Jun 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
(bold added for emphasis only)
Did you not understand the bolded line? It's telling you specifically that it can't resolve that name in DNS, or the IP address can't be reached. And have you looked at the mysql command or read the man pages? The -H option tells you specifically how to connect to a remote host directly, with no need for an SSH-and-script-run.
I think I don't understand is you because I specifically made it clear that I want to connect to several computers on a network and what I want to do is I want the result of you pulling out once you connect the computer by ssh to insert it into a database but I don't want to connect to computer B to insert it into computer A but I want the result of computer B to insert it into the database locally, I said to myself now if I understood?

and the SSH error appears when I try to connect through SSH when I send the IP and the execution of the Local script, the IP has the port enabled and I don't know why the error is thrown to me.

Translated with www.DeepL.com/Translator
 
Old 06-28-2018, 07:16 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by m0rt View Post
I think I don't understand is you because I specifically made it clear that I want to connect to several computers on a network and what I want to do is I want the result of you pulling out once you connect the computer by ssh to insert it into a database but I don't want to connect to computer B to insert it into computer A but I want the result of computer B to insert it into the database locally, I said to myself now if I understood?
Nope, sorry...you aren't clear at all, and your 'solution' is still poor. If you want to insert things into your local DB from a remote DB, you can AGAIN call the remote DB directly, download whatever data you want **WITHOUT SSH SCRIPTS**, then manipulate that data for insertion locally.
Quote:
and the SSH error appears when I try to connect through SSH when I send the IP and the execution of the Local script, the IP has the port enabled and I don't know why the error is thrown to me.
Right; again, either you're using a host name that DNS can't resolve, or something is blocking the IP address (bad route, wrong address, whatever). The error is very clear.
 
Old 06-28-2018, 07:19 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP: Also the artificial translation (and the lack of [code] and [/code] tags) makes your posts virtually incomprehensible.

Last edited by NevemTeve; 06-28-2018 at 07:20 AM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
API for CRUD and Pub/Sub -- CRUDS? ttk Programming 1 05-21-2018 07:16 AM
[SOLVED] Not able to import MySQL database using SSH dreamcoder Linux - Server 6 08-03-2012 08:50 AM
NFS FC5 and crud. augurseer Linux - Networking 3 06-04-2006 07:04 PM
Ubuntu stuck with the same driver crud as debian? Wolvenmoon Ubuntu 11 08-23-2005 02:08 PM
RH7.3 Install ALL except GUI crud? ifm Linux - Distributions 3 06-09-2002 03:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration