'Can I use a tilde ( ~ ) in a mysqldump cronjob? Linux Cron is not running

I was having the same issue as this person and this person, where my command worked locally but inside of a cron task, nothing happened.

Here is what I am trying to run:

/usr/bin/mysqldump -u root -ppassword database_name > ~/Documents/dump.sql

This works locally when I type I straight into my terminal! It might throw an error saying:

mysqldump: [Warning] Using a password on the command line interface can be insecure

But it still it works. It even works if I put in the user root before the command.

Now, here is the CRON (just trying to run it every minute to test if it works)

*/1 * * * * root /usr/bin/mysqldump -u root -ppassword database_name > ~/Documents/dump.sql

And... nothing happens. What I saw from this question and [this person] was that it was a matter of syntax. I cannot figure out WHY this CRON will not run!



Solution 1:[1]

You should try using $HOME rather than ~ as tilde expansion is not reliable in a cron job.

See this as an example. Here is more information about tilde expansion.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cezary Dro?ak