Mysql command after a SSH connection (Script)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mysql command after a SSH connection (Script)
# 1  
Old 10-28-2010
Mysql command after a SSH connection (Script)

Hi all,

Im new at scripting and i need to run a few commands at work every hours so i decide to make a script but on 1 of the steps i have a the follwoing problem:

The command i do is this:
Code:
#!/bin/bash
ssh root@asdasd001  'mysql -h A-db-1 -uroot -password --execute "show slave status"'

and when i run the script the error it appear is:
Code:
bash-3.00# ./test
sh: mysql: not found

Thanks in advance.
Br
# 2  
Old 10-28-2010
You need to set the environment with something like this, to get $PATH and other local supporting variables the shell and mysql app need:
Code:
ssh root@asdasd001  '. ./.profile ; mysql -h A-db-1 -uroot -password --execute "show slave status"'

(Does this really require the power of root? Using a sledge to set tacks eventually gives hurt fingers.)
# 3  
Old 10-28-2010
Thanks for the fast response but the problme persistss Smilie

Just for clearing out of the script i just do:
Code:
ssh asasasa
        and on the asasasa machine i just run the command
mysql -h A-db-1 -uroot -pass --execute "show slave status"

Code:
#!/bin/bash

ssh asasasa '../.profile ; mysql -h A-db-1 -uroot -pass --execute "show slave status"'


Code:
bash-3.00# ./test
sh: ../.profile: not found
sh: mysql: not found

# 4  
Old 10-28-2010
Just use the full PATH of mysql. That is what most of us do. When running commands from scripts, as a common best practice, always use the full path.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies

2. Shell Programming and Scripting

Timeout to abolish ssh connection command it takes too long

Hi, I am running a ssh connection test in a script, how can I add a timeout to abolish the process if it takes too long? ssh -i ~/.ssh/ssl_key useraccount@computer1 Thank you. - j (1 Reply)
Discussion started by: hce
1 Replies

3. UNIX for Dummies Questions & Answers

Script that tries to connect via SSH till connection is up

Hey, I need a script that tries to connect via SSH to a remote server and that remote server might not be up yet, so retry until succeed the error message I get if the server is not up yet is: ssh: connect to host 127.0.0.1 port 40001: Connection refused any idea of a good way to do it ? ... (5 Replies)
Discussion started by: OdedOvdat
5 Replies

4. Shell Programming and Scripting

ssh connection through shell script with no interruption

Hi all, I need ssh in shell script. My requirement is: - Take user_name and password from user (in PHP) - Pass this to shell script which will: - connect via ssh - Run sql query - Pass the results back in PHP - Put the results to website. I know PHP has libraries for ssh and ftp, but... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

5. Shell Programming and Scripting

Passing password in script for ssh connection - no except

Used the script posted on forum - unix.com/shell-programming-scripting/21597-script-change-passwords-same-user-multiple-servers.html but the last question posted on this seems to be still unanswered, tried different things with no success, can someone help giving an way to pass the password via... (5 Replies)
Discussion started by: sapadmin
5 Replies

6. Shell Programming and Scripting

SSH Connection drops - but does my script keep running?

Hello there. I'm fairly new to Linux, but I am connecting via SSH and PuTTY to a remote server, and I am running a fairly heavy MySQL script in a PHP page. Our connection here is dodgy to say the least and I get continuous disconnections. My question is, when I get disconnected, does my... (4 Replies)
Discussion started by: christatedavies
4 Replies

7. Shell Programming and Scripting

how to terminate ssh connection without terminating script

Hi all, I connect with SSH connection to remote machine in the script and ı want to logout at half of the script then continue to script. If ı write exit in the script it terminates script not SSH connection. How can i do that please help me (1 Reply)
Discussion started by: fozay
1 Replies

8. Shell Programming and Scripting

ssh connection script

Hi all, I'm writing a script that chooses the best computer available in an open lab. The script works great except every now and then there is a dead computer in the lab that begins the ssh handshaking, but freezes after the following: debug1: Offering public key: When the script happens... (2 Replies)
Discussion started by: x-375HK-x
2 Replies

9. Shell Programming and Scripting

Remote SSH Connection Using Script

Hi, I am new to Shell Scripting. Can anybody help me in writing a Script Which Could Login from a Unix box to a Remote Unix box which accepts the user credentials automatically and display the result for checking the Disk Space Utilisation (Without running any SSH agent). (1 Reply)
Discussion started by: ajith_tg
1 Replies

10. Shell Programming and Scripting

Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running). I have a scp command, as follows: scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR ... (8 Replies)
Discussion started by: dmilks
8 Replies
Login or Register to Ask a Question