I have a problem with the problem with syntax of a cronjob in plesk 12.5 , I use the following syntax in plesk 12.0 and it runs fine, however in plesk 12.5 it won't work.
mysqldump -u user -ppassword database | gzip > /var/www/vhosts/domain.com/backupmysql/backup$( date +"\%Y_\%m_\%d_\%H_\%M" ).sql.gz
can anybody help me with the correct syntac for plesk 12.5
Try to use
/usr/bin/mysqldump -u user -ppassword database | gzip > /var/www/vhosts/domain.com/backupmysql/backup$( date +"\%Y_\%m_\%d_\%H_\%M" ).sql.gz
At least command like
/usr/bin/mysqldump -uadmin -pcat /etc/psa/.psa.shadow psa | gzip > /var/www/vhosts/domain.com/backup$( date +"\%Y_\%m_\%d_\%H_\%M" ).sql.gz
works like a charm.
date: command not found -: date: command not found
Make sure that you have /bin/date installed, it is part of coreutils package.
Related
Hi everyone would do with some advise
Can not get this simple task working
0 17 * * * wget -m ftp://usarname:password#host.com:port/remote/folder -P /local/folder
what im doing wrong ?
if i run it in terminal line:
wget -m ftp://usarname:password#host.com:port/remote/folder -P /local/folder
it is working as expected but if i add under crontab -e nothing happens.
I would like cron job to check files every day at 17:00 for changes.
thanks in advance
Forgot to restart cron service. Now just need to make it all end to end encrypted.
if you make any changes to services do not forget to restart them :)
restart cron
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!
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.
I am trying to execute a php script in my linux server. the script will run everyday at 8 am. I have uploaded my crontab in linux server and the php file update1.php Script in my crontab is given below. But this isnt updating my databse. where am i doing wrong ? Am i missing something here. Thanks in advance.
crontab
0 8 * * * http://www.mywebsite.com/update1.php
You can use --spider option of wget for this purpose.
0 8 * * * wget --spider http://www.mywebsite.com/update1.php
--spider indicates not to download anything (we just want to go through the pages, that’s all)
This line/code in your crontab:
http://www.mywebsite.com/update1.php
is not an execution of the script, it's just the url to it. You should download the php script, and put it locally on your linux server. That would make things simpler and much more reliable.
I would login to your linux server, use wget to download the script, chmod it to make sure it's executable, and mv it to wherever you want on your server:
wget http://www.mywebsite.com/update1.php -O update1.php
chmod 755 update1.php
mv update1.php /path/to/where/you/want/script
Then now that you have the script locally on your linux server, edit your crontab (crontab -e), and add the following line:
0 8 * * * /path/to/where/you/want/script/update1.php
I am having an issue that I can not find any information for while doing an extensive google search.
I have a linux cron, running via crontab, that works great until I try to add a variable date to the title of the file. BUT.. When I run the same command outside the cron, just from the command line, it works fine.. Also, the cron does work if I take out the date part.
Command line code that works:
sudo mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gz
Cron that works:
15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database.sql.gz
Cron that DOESN'T work:
15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_`date '+%m-%d-%Y'`.sql.gz
I am not understanding why I can not use the date function while inside a cron?
Everything I find says I can, but in practice, I can not.
Server details:
Ubuntu 12.04.5
Thank you for any insight.
You just need to use escaping % sign
* * * * * touch /tmp/foo_`date '+\%m-\%d-\%Y'`.txt
Result:
[root#linux tmp]# ls -l /tmp/foo_*
-rw-r--r-- 1 root root 0 Apr 18 02:17 /tmp/foo_04-18-2015.txt
Try replacing the backticks with $() and escaping your %s, such as:
15 2 * * * root mysqldump -h mysql.url.com -u user -pPassword intravet sites | gzip > /mnt/disk2/database_$(date '+\%m-\%d-\%Y').sql.gz
I only mention removing the backticks because you will end up having all kinds of escaping problems later in your coding endeavours. Stick with using $() for command substitution.
I have written a cron job for dumping my mysql database but it's not working.
Here it is.
/usr/bin/mysqldump -h localhost --user=user --password=mypass --databases dbname | gzip > /home/username/site_dir_name/uploads/backup.sql.gz
I am using cpanel.
Try this
mysqldump -u{user name without space} -p{password without space} Database_name | gzip -9 > /home/backup_$(date +"\%Y.\%m.\%d.\%S.\%N").sql.gz 2> /home/db.log
add this line into cron job.