ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
(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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.