LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-09-2012, 01:33 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
expect and spawn fails with ;


HOST="127.0.0.1"
USER="root"
PASS="pass"

#check="mysql -e \\\"show databases;\\\"";
check="mysql -e \\\"show databases\\\""



VAR=$(expect -c "
spawn ssh $USER@$HOST $check
expect \"password:\"
send \"$PASS\r\"
expect \"\\\\$\"
")

echo "==============="
echo "$VAR"



i absolutely need to pass a ; after the mysql command but expect and spawn does not allow me to do so.
Can anyone please help me how can i achieve that
 
Old 09-09-2012, 03:43 AM   #2
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Rep: Reputation: 79
Maybe you need to escape the ; as well?

I would suggest using an seperate expect script for doing the ssh.
 
1 members found this post helpful.
Old 09-09-2012, 04:37 AM   #3
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by deadeyes View Post
Maybe you need to escape the ; as well?

I would suggest using an seperate expect script for doing the ssh.
can you please tell me how
i was trying to repeat the expect but it fails the 2nd one does not execute

VAR=$(expect -c "
spawn ssh $USER@$HOST $check
expect \"password:\"
send \"$PASS\r\"
expect \"\\\\$\"
")

echo "==============="
echo "$VAR"

VAR1=$(expect -c "
spawn ssh $USER@$HOST $check
expect \"password:\"
send \"$PASS\r\"
expect \"\\\\$\"
")

echo "==============="
echo "$VAR1"

please help
 
Old 09-09-2012, 07:15 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You seem to be trying to login at the Linux level with ssh, but you also need to login to mysql separately.
I know the dba acct in mysql is called 'root', but its got nothing to do with the Linux root acct; you'll need a separate set of credentials.
Can I also persuade you not to use plaintext passwds for ssh (use ssh auth-keys) and disable root via ssh entirely, even on the loopback interface. You never know who's 'listening' and its a bad habit to get into.

If MySQL is listening on 127.0.0.1, you can just use the mysql client direct ie no ssh reqd.
 
1 members found this post helpful.
Old 09-10-2012, 12:02 AM   #5
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Rep: Reputation: 79
Quote:
Originally Posted by chrism01 View Post
You seem to be trying to login at the Linux level with ssh, but you also need to login to mysql separately.
I know the dba acct in mysql is called 'root', but its got nothing to do with the Linux root acct; you'll need a separate set of credentials.
Can I also persuade you not to use plaintext passwds for ssh (use ssh auth-keys) and disable root via ssh entirely, even on the loopback interface. You never know who's 'listening' and its a bad habit to get into.

If MySQL is listening on 127.0.0.1, you can just use the mysql client direct ie no ssh reqd.
You are making a point here.
It depends on what you want to do. But for most cases public/private keypairs would make login possible without password.
By default the mysql root user can login without password from the host were it is running.

THen you can just do:
ssh $user@$host "mysql-command"
In that case you don't even need expect.

Last edited by deadeyes; 09-12-2012 at 05:48 AM. Reason: Typo
 
1 members found this post helpful.
Old 09-10-2012, 01:01 AM   #6
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by deadeyes View Post
You are making a point here.
It depends on what you want to do. But for most cases public/private keypairs would make login possible with password.
By default the mysql root user can login without password from the host were it is running.

THen you can just do:
ssh $user@$host "mysql-command"
In that case you don't even need expect.
this is just a test
i can use mysql perfectly
im just trying to find out how can i bypass the ; in the script
my ssh and mysql works perfectly but the problem is i want to automate things and i have a lot of commands to pass
please help thanks in advance
 
Old 09-10-2012, 08:36 PM   #7
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
By default the mysql root user can login without password from the host were it is running.
I think that's only at the initial install; It shouldn't be left that way & most installs expect/tell you to set a (mysql) root user passwd.

Anyway, to pass a bunch of sql cmds, use a file
Code:
mysql <file.sql
which also solves the ';' qn.
 
Old 09-12-2012, 05:50 AM   #8
deadeyes
Member
 
Registered: Aug 2006
Posts: 605

Rep: Reputation: 79
Quote:
Originally Posted by chrism01 View Post
I think that's only at the initial install; It shouldn't be left that way & most installs expect/tell you to set a (mysql) root user passwd.

Anyway, to pass a bunch of sql cmds, use a file
Code:
mysql <file.sql
which also solves the ';' qn.
Correct, this is the initial install.
The second thing you note is true, however you can put a password for root from another host but keep it without for the localhost.
Anyways, that's a bit off-topic
 
  


Reply

Tags
bash, expect, spawn


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect spawn shell commands finwe Linux - Newbie 3 09-19-2011 12:27 AM
Expect: spawn id expr4 not open gabes Linux - General 3 09-15-2011 12:07 PM
[SOLVED] spawn with Expect script najee1987 Linux - General 5 05-25-2011 01:53 AM
send: spawn id exp1025 not open in tcl/expect bharatbsharma Programming 3 04-22-2010 02:04 AM
Expect interpreter, spawn and cat Ricio Programming 11 08-16-2008 05:55 PM


All times are GMT -5. The time now is 10:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration