Help Required - facing error when trying to connect to a mysql by ssh to another server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Required - facing error when trying to connect to a mysql by ssh to another server
# 1  
Old 11-19-2014
Question Help Required - facing error when trying to connect to a mysql by ssh to another server

Hi

i am new to unix shell scripting i have the below requirement
connect to server B and then connect to mysql in the server B and query for a particular record and capture that value

but when i perform this i am facing an error

can u guys help me on thisSmilieSmilie

Code:
$(ssh user@serverB<< EOF1
getCycleID=$(mysql -uehpoll -pqanra5 -s -N<< EOF
use EdgeHealth;
/* Query to get the last cycle_id that is in ready to collect state for cmts cycle type*/
select max(cycle_id) from polling_cycles where cycle_type="cmts" and collection_status="ready_to_collect"
EOF
)
EOF1
)
echo $getCycleID

when executing the above script facing the below error

Error
Code:
./Collector_Poller.sh: line 2: /[: Permission denied
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
./Collector_Poller.sh: line 4: user@ServerB: command not found

# 2  
Old 11-19-2014
create this script locally:
Code:
getCycleID=$(mysql -uehpoll -pqanra5 -s -N<< EOF
use EdgeHealth;
/* Query to get the last cycle_id that is in ready to collect state for cmts cycle type*/
select max(cycle_id) from polling_cycles where cycle_type="cmts" and collection_status="ready_to_collect"
EOF
)
echo $getCycleID

Let's call it getcycle.sh. I am making up the home directory for user on serverb, you change it.
One time only:
Code:
scp getcycle.sh user@serverb:/home/user/
ssh user@serverb ' chmod +x /home/user/getcycle.sh'

Now your local script becomes:
Code:
getCycleID=$( ssh user@serverb:/home/user/getcycle.sh)

# 3  
Old 11-20-2014
Hi Jim,

i tried by creating a getcycle.sh locally and followed the steps suggested , but facing the below error when executing

Code:
ssh: ServerB:/home/user/getcycle.sh: Name or service not known

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

2. Red Hat

Xming Vs ssh connect to RHEL server from Windows machine

I am able to connect a RHEL server from my Windows machine using Putty (via ssh). My question is what is the advantage of using Xming instead of Putty? Is it that Xming would enable a graphical connect from the Windows machine to RHEL server? I hope my question is clear that what is the... (9 Replies)
Discussion started by: RHCE
9 Replies

3. Red Hat

unable to connect remote server using ssh

hi all i am unable to connect remote server using ssh but i am able to ping the server ssh service is running. (5 Replies)
Discussion started by: nikhil kasar
5 Replies

4. Shell Programming and Scripting

Error in installing mysql on unix server

Hi , I am trying to install mysql but getting below error $# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) can anyone provide me this file 'mysql.sock' Thanks (6 Replies)
Discussion started by: aish11
6 Replies

5. Shell Programming and Scripting

[SSH] Need to connect to remote server as different user and without password

I have a task requiring that USER_A run a script, which connects to HOST_B as USER_B and does not ask for a password. If I am logged in on HOST_A as USER_B, I can connect to HOST_B without a password, no problem. However, if I try running ssh with the command line "ssh USER_B@HOST_B" while... (3 Replies)
Discussion started by: Totengraber
3 Replies

6. Shell Programming and Scripting

Trying to connect MYSQL server from HP-UX

Hi everyone, I have an urgent requirement to get some table data from Linux-MYSQL server from HP-UX with oracle database.Is there any way we can get connected through Shell script from HP-UX and issue select on mysql to get some table data? Please help me out. (7 Replies)
Discussion started by: kashik786
7 Replies

7. Shell Programming and Scripting

shell script for how to connect to a remote server by using ssh

i want to connect to a remote server through ssh. i have to also provide password within that script. after connecting to the remote server i want to do some operations like grep,cd etc can u pls help me to wite a script. Thanks (1 Reply)
Discussion started by: millan
1 Replies

8. Shell Programming and Scripting

how to connect to server with ssh to check process size

Hello i have to connect to 11 servers to check the process size on every server. how to that with shell scripting using ssh regards (7 Replies)
Discussion started by: mogabr
7 Replies

9. UNIX for Dummies Questions & Answers

connect to server using ssh

hi, i have script that connects to a unix server. however, i want to add condition that if it cannot connects in 10 attemps, it will send email to me. while -a ${COUNT} -lt 10] ./connect to server. if status <> 0 then email to me. fi Thanks a lot. (0 Replies)
Discussion started by: tungaw2004
0 Replies

10. Shell Programming and Scripting

Not able to remotely connect to server using ssh

Hi, I am trying to run the below command in perl but when the perl script is executed it prompts a error message saying " ssh: <username>: Name or service not known ". Not able to understand this as this command runs perfectly on the server prompt. ` ssh <username>@pus4026dev df -k >>... (2 Replies)
Discussion started by: be2sp1
2 Replies
Login or Register to Ask a Question