Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
CMD="use metadata; select * from usernames; select * from personData; select usernames.SNo, 
usernames.DataTelid, usernames.UName, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid into outfile '/tmp/querydb';"
ssh [USER-NAME]@[REMOTE-HOST] 
mysql -h HOST  -u USERNAME -pPASSWORD -e "$CMD"  < /tmp/querydb

From server A, I login to server B which has the mysql database. The querydb file is snot suppose to be created on server B but server A. I am stuck and how to go about this?

share|improve this question
add comment

1 Answer

Well, I see two issues:

  1. You're ssh'ing into server B, obtaining a shell there, and then executing the mysql command. No amount of output redirection performed on server B will be able to get files back to server A.

  2. Your output redirection is going in the wrong direction.

Try this:

ssh user@host "mysql -u USER -pPASSWORD -e \"$CMD\"" > /tmp/querydb
share|improve this answer
    
do you mean like this? CMD="use itTools; select * from usernames; select * from personData; select usernames.SNo, usernames.DataTelid, usernames.UName, personData.ActiveInactive from usernames, personData where usernames.DataTelid=personData.DataTelid;" ssh user@host "mysql -u USER -pPASSWORD -e \"$CMD\"" > /tmp/querydb –  Piyush Saxena Oct 22 '12 at 16:25
    
Yes, that's correct. –  EEAA Oct 22 '12 at 16:44
    
@ErickA I am trying to find the meaning of: diff filename 1 filename2 | grep '^[<>]' | sed "s/^> (.*)/\1 some string/;" –  Piyush Saxena Oct 23 '12 at 15:52
    
@PiyushSaxena Post another question. Do not use comments for anything other than, well, comments. –  EEAA Oct 23 '12 at 15:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.