expect script stopped to after migration from Ubuntu 10.04 to 12.04 - mysql

I have expect script that does backups.
It worked fine on different machines and OSes but it does not work on Ubuntu 12.04
#!/usr/bin/expect -f
set folder [lindex $argv 0]
set password "PassWD"
spawn mysqldump -u root -p mydb01 --result-file=/home/myuser/backup/$folder/$
expect "*assword:"
send "$password\n";
#interact
wait
I tried to change expect line to
expect "Enter password:"
or
expect "Enter password: "
It does not work and it asks me to enter password like
Enter password:
I checked that mysql password is correct.
That script worked fine since 2010 on different OSes.
UPDATE
I created another cloud server with same OS and same data.
Everything works there. I have no idea why it does not work on first one.
I guess servers may have old commodity harddrives and it corrupted some file.

Can you try like this,
expect "password"
or
expect -re ".*word"
Please make sure you are using the switch '-re' with expect when you want to use regular expressions.

Related

Can't login to unix mysql user

I'm trying to login to my mysql user created by the MySQL installation in bash shell.
So the command I'm trying to do is:
sudo -i -u mysql
But, it does nothing (nothing printed out in the console, not connected to any user whatsoever, etc...).
EDIT: The return value of the command is 1 though.
Here is the mysql user line in the /etc/passwd file:
mysql:x:89:89::/var/lib/mysql:/bin/false
I'm running on ArchLinux 64bit and the user I'm trying to connect to is local (no connection to a remote server whatsoever).
I'm trying to understand why I can login with any other user (like postgres, root, ...) but not mysql.
Hope you can help!
This is intended behaviour. When you compare the /etc/passwd line with other lines you'll notice that the user mysql has /bin/false setup as the shell while others have usually /bin/sh or sth. similar.
When you sudo to mysql you actually get a login for about a millisecond or so and then his "shell" gets executed. /bin/false immediately returns with rc=1 (that's the only purpose of the false command).
This is some kind of "trick" to prevent users from logging in as user mysql although the account is otherwise fully operational.
The user mysql may even have a valid password and be enabled but due to his odd shell setting you cannot login as him. Sometimes these technical users have /usr/bin/passwd set as their shell. Then you can only sudo to that user and change his password, nothing else.

mysql-proxy not running lua script

I know there are many mysql-proxy questions on SO, however I have read through many of them and none seem to solve my problem. I am simply trying to get mysql-proxy up and running, with the eventual purpose of rewriting some queries that go through the proxy. I am using ubuntu 14.04, I have mysql-proxy version 0.8.1, and mysql version 5.5.37. To start mysql-proxy I run the following line on the command line
sudo mysql-proxy --defaults-file=mysql-proxy.cnf
where the file mysql-proxy.cnf looks like the following:
[mysql-proxy]
log-file= /var/log/mysql/proxy-error.log
log-level= debug
admin-lua-script= /usr/lib/mysql-proxy/lua/admin.lua
proxy-lua-script= /path/to/lua/script/example.lua
admin-username = myusername
admin-password = mypassword
proxy-skip-profiling = true
proxy-address = localhost:4040
proxy-backend-addresses = localhost:3306
plugins = proxy,admin
My example.lua script is very simple, and meant only to verify that the mysql-proxy query is being altered. example.lua is pasted below
-- first_example.lua
function read_query(packet)
if string.byte(packet) == proxy.COM_QUERY then
print("Hello world! Seen the query: " .. string.sub(packet, 2))
end
end
Since I don't run this with the --daemon flag, when I run that line above in the command line it just loops indefinitely, which is expected.
Finally, in separate terminal session, I run the following on the command line and enter my password in order to connect with the proxy
mysql -u myusername -p -h localhost -P 4040
I then select a database to use, and run a simple SELECT query on one of the tables. Based on multiple articles/tutorials I've read on mysql-proxy, my first console session, the one that ran mysql-proxy, should print out some data based on the example.lua file. However this does not happen, in fact nothing happens.
I'm not sure if the following bit of information makes any difference, but in my "my.cnf" mysql configuration file, I have these couple of lines
bind-address = 255.255.255.255
#bind-address = 127.0.0.1
where I have replaced my actual ip address with 255.255.255.255 because I do not want to display my ip address publicly.
Please, I have been trying to figure this out for several days, and no amount of new lua scripts, or changing the host:port parameters in the mysql-proxy.cnf file have solved anything. I

Ruby: How do I return a MySQL query up an SSH tunnel?

//update: when feeding mysql passwords, -ppassword works. -p password does -not- work. Problem solved.//
We have hundreds of databases on our work servers, and I'd like to write a ruby script that automates the process of creating duplicate versions of them on my local machine for development purposes.
I've been trying to use net-ssh to create the tunnel, but (host, user, pass, etc. are censored for obvious reasons):
require 'net/ssh'
HOST = 'xxx'
USER = 'yyy'
PASS = 'ppp'
Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
puts "inside ssh tunnel"
puts ssh.exec!('ruby -v')
puts ssh.exec!('mysql -u zzz -p pswrd -h c3 will_il_raw -e "select * from deeds limit 1"')
end
results in the output:
inside ssh tunnel
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
followed by an indefinite hang. Interestingly, if I ssh into the same computer via the console, 'ruby -v' returns 1.9.3. If I enter that mysql query there, it successfully returns one line of the named table.
I assume the solution has something to do with port forwarding, but here my limited knowledge begins to fail me utterly.
The machine running the mysql server is not the same machine as I am accessing it from, which is not, in turn, the machine I am actually sitting at. I need to connect the dots and apparently have no idea how to go about this properly.
Any protips would be much appreciated.
In MySQL syntax, when feeding a password using -p[password], there is no space between -p and the password.
Because the script's version of the syntax had a space, the result of the query was a prompt requesting the password, which caused the hang on the far end of the SSH tunnel.

Expect scripting: remote database backup automation

I'm looking for a kind of remote database backup automation.
Then, I came across a scripting language which commonly used for administrative tasks, "Expect scripting" and I believe it could serve my purpose very well.
what I'd like to do is I want to perform login to a remote server using the following bash script from my local linux box. (supposed everything has been set properly, SSH authentication via generated key pair, so no password is required)
For the most important part, I'd like to send a mysqldump command to perform backup for my database on that server.
#!/usr/bin/expect
set login "root"
set addr "192.168.1.1"
spawn ssh $login#$addr
expect "#"
send "cd /tmp\r"
expect "#"
send "mysqldump -u root -ppassword my_database > my_database.sql\r"
expect "#"
send "exit\r"
The only problem I found here was after the line send "mysqldump -u root....... ".
It was never waiting until the process to finish, but immediately exit the shell with 'send "exit\r"' command line.
what do I do to make it waits until mysqldump command finish and log off the SSH properly?
I don't know the answer to your question: add exp_internal 1 to the top of the program to see what's going on.
However, since you have ssh keys set up, you don't really need expect at all:
ssh $login#$addr 'cd /tmp && mysqldump -u root -ppassword my_database > my_database.sql'

Weird mySQL behavior in Ubuntu 10.10

I'm having some serious trouble with a freshly installed copy of mySQL server under Ubuntu 10.10. I installed with apt and supplied a password at that time. Installation went fine, but the server is behaving very strangely.
First, to test the database, I created a php file with
mysql_connect("localhost", "root", "myPassword") or die(mysql_error());
where myPassword is the one I entered when it asked, during installation. That gave me an access denied error. I tried to shell into the mySQL server to pursue a solution I read about. The normal syntax didn't work, and to get anything but "access denied", I had to do
mysql -u root password myPassword
However, instead of a mysql shell, it just spits out a list of parameters and variables. So at this point, I'm stumped; I haven't worked with mySQL through a command line in a couple of years, but none of this behavior is familiar, and I can't find a way to interact with the server.
Any help would be appreciated.
The mysql command-line parameter for supplying a password is -p, not password. You should also leave out spaces. For example:
mysql -uroot -pmyPassword
If you don't want to risk your password being exposed...
mysql -uroot -p
...will prompt you for your password and hide the characters as you type them.
If you have apparmor installed (this is default) it can cause problems when you go outside the narrowly-defined defaults set up by ubuntu.
The things that mysql is allowed to touch is defined here: /etc/apparmor.d/abstractions/mysql
If you've put your socket file elsewhere, you would get an access-denied message.
To look at things more closely, run your mysql client like so:
strace -e file mysql <blah blah>
This will print out any system-level file operations on stderr. You can then see exactly which operation is causing the permissions error. If you don't see an issue, you might use -e network instead, to see network operations.