2
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?

EEAA
  • 109,363
  • 18
  • 175
  • 245
Piyush Saxena
  • 21
  • 1
  • 2

1 Answers1

1

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
EEAA
  • 109,363
  • 18
  • 175
  • 245
  • 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