I have access to a remote server that I don't fully control and prefer to have my automated scripts that do things on that server live locally. I've found that not all commands executed inline with ssh behave the same. Example that is run in a cron job:
ssh firstname.lastname@example.org "mysqldump -u dbuser -p'pass$word' dbname > backup.sql"
The above (and many variants of it) returns
mysqldump: Got error: 1045: Access denied for user 'dbuser'@'localhost' (using password: YES) when trying to connect. But i have verified the password is correct by
ssh to the server and then manually running
mysqldump -u dbuser -p'pass$word' dbname > backup.sql and everything works.
Another example is running something like:
ssh email@example.com history > history.txt
The above output is empty but if I
ssh to the other machine and then manually run
history > history.txt, the output is as expected.
If I do something like the following, everything works as expected:
ssh firstname.lastname@example.org ls > ls.txt
But I would still eventually run into another command that does not working as expected even if i include them in quotes when running inline and redirecting output locally. It's as if the shell is reading stuff with different variables attached depending on how it's accessed.
How do i execute any command inline ssh as if I'm typing it manually but direct output to local machine?