mysqldump with ssh connection in shell script
13,683
Solution 1
You need to escape the > symbol. Try this:
ssh user@host mysqldump -uusername -hlocalhost -ppassword --all-databases \> /home/user/sqlfile.sql
Solution 2
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
Comments
-
9edge almost 2 years
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?