LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   expect and spawn fails with ; (http://www.linuxquestions.org/questions/linux-newbie-8/expect-and-spawn-fails-with-%3B-4175426320/)

figure20012 09-09-2012 02:33 AM

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

deadeyes 09-09-2012 04:43 AM

Maybe you need to escape the ; as well?

I would suggest using an seperate expect script for doing the ssh.

figure20012 09-09-2012 05:37 AM

Quote:

Originally Posted by deadeyes (Post 4776022)
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

chrism01 09-09-2012 08:15 PM

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.

deadeyes 09-10-2012 01:02 AM

Quote:

Originally Posted by chrism01 (Post 4776401)
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.

figure20012 09-10-2012 02:01 AM

Quote:

Originally Posted by deadeyes (Post 4776531)
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

chrism01 09-10-2012 09:36 PM

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.

deadeyes 09-12-2012 06:50 AM

Quote:

Originally Posted by chrism01 (Post 4777303)
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 ;)


All times are GMT -5. The time now is 06:38 PM.