I'm using a shell script that opens a ssh connection and creates an sqldump.
But, when I use mysqldump
in the shell script it gives me the error:
"No such file or directory"
This is the line I use:
ssh user@host mysqldump -uusername -hlocalhost -ppassword --all-databases > /home/user/sqlfile.sql
The mysqldump
works when i use it in an opened ssh connection or at the server in the commandline.
So my question is why do I get the error and why can't I run the mysqldump command in a shell script?
You can also enclose your ssh remote commands in quotes. e.g.
ssh user@host "mysqldump -uusername -hlocalhost -ppassword --all-databases > /home/user/sqlfile.sql"
That way, if you want to scp the dump to your local folder all in one, you can:
ssh user@host "mysqldump -uusername -hlocalhost -ppassword --all-databases" > /home/user/sqlfile.sql
You need to escape the > symbol. Try this:
ssh user@host mysqldump -uusername -hlocalhost -ppassword --all-databases \> /home/user/sqlfile.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With