Because I am always running out of space, I want to delete several zip files automatically by creating a cron job in Plesk. I did some research, but apparently I am doing something wrong, because nothing is happening.
Running Plesk 12.
Here is the cron job I am currently trying to use:
/usr/bin/find /var/www/vhosts/sitename.com/httpdocs/backups/ -type f -name '*.zip' -mtime +2 -exec rm {} \;
What am I doing wrong here?
Thank you in advance.
//update
I took a look at the link that michael posted and changed my cron job to:
find /var/www/vhosts/sitename.com/httpdocs/backups/ -type f -mtime +2 -name '*.zip' -execdir rm -- {} \;
But still no dice. It doesn't remove the .zip files. Sigh. This should have worked right?
Just create corresponding bash script with this command and run this script as cron job.
Well I didn't make a mistake with the cron job, but I had to change the following setting:
Access to the server over SSH
from
bin/bash (chrooted)
to
/bin/sh
That fixed everything for me. Now the cron job is working.
So people experiencing this problem and are on Plesk 12, should do the above to fix problems with their cron jobs.
Related
Similar to this question I want to make a task scheduler script to copy NEW files (last 24h) to a new folder.
I try to use this code:
find /volume1/start/ -mtime -1 -type f -exec cp -r {} /volume1/target/ \;
but it delivers a 1kb filename.pdf#SynoEAStream file instead of the file itself.
How can I fix that?
Ok actually it seems to work as supposed I actually just had the wrong file modification date in the files where it didn't work. The script additionally copies some "useless" #SynoEAStream files whicht I now avoid by only looking for pdf-files which ist what I wanted.
find /volume1/TestScan/start/ -mtime -1 -type f -iname '*.pdf' -exec rsync -r {} /volume1/TestScan/ziel/ \;
Maybe its helpful for someone
I'm setting up a webserver with Plesk on Ubuntu 18.04 and I would like to use a part of the space I've available to store security footage. I succeeded in automatically uploading the photos and videos to the correct folder, but the problem is that they are not automatically removed, so that the server is full of security images. I upload the footages to a folder on the server that is also available from the internet (secured). I did some research on the internet to a cron job that automatically deleted the files older than 7 days where I found this:
find /var/www/vhosts/path to files/* -mtime +7 -exec rm -f {} \;
I also found that you can name a file to, for example: delete-files and which can be executed with crontab -e. (Yes, I made it executable;-)
I added this cron to run every hour and stated that I received notifications from the cron. Now, however, I get the following output: find: missing argument to `-exec '
Is there anything else that I need to share? Like logs?
change find /var/www/vhosts/path to files/* -mtime +7 -exec rm -f {} \;
to
find /var/www/vhosts/path to files/ -mtime +7 -exec rm -f {} \;
the * is unnecessary in the path
Can you try this as well?
find /var/www/vhosts/path to files/ -mtime +7 | xargs rm -f
I'm looking for help to make a cron job that every 12 hours will delete all .zip files from a subfolder in my hostgator hosting account.
http://prntscr.com/7rr22d
After some google research I tried this command but nothing seems to happen
find /home/username/domain.com -type f -name "*.zip" |xargs rm
What should I put in the "Command:" field ?
Maybe try:
find /home/username/domain.com -name "*.zip" -exec rm -rf {} \;
I found this bash script online that I want to use to delete files older than 2 days:
#!/bin/bash
find /path/to/dir -type f -mtime +2 -exec rm {} \;
I setup a cronjob to run the script (I set it a couple of minutes ahead for testing, but it should run once every 24 hours)
54 18 * * * /path/to/another/dir/script.sh
I exit correct so it updates the cronjob.
Why does it not delete the files in the directory?
What if you try dumping an echo at the end of the script and log the output
cron1.sh >> /var/log/cron1.log
You could try this but I'm not sure it will work
--exec rm -rf {}
Most cron jobs do not have PATH set. You must fully qualify the find command.
#!/bin/bash
/usr/bin/find /path/to/dir -type f -mtime +2 -exec rm {} \;
If you capture the stdout and stderr as recommended by damienfrancois, you'd probably see the message "command not found: find". If you didn't capture the stdout and stderr, cron usually will send the output to the cron job owner's email, unless configured not to do so.
In linux shell, When I run
ls -al -t
that show the time of files.
How to cp/rm files by time? just like copy all the files that created today or yesterday. Thanks a lot.
Depending on what you actually want to do, find provides -[acm]time options for finding files by accessed, created or modified dates, along with -newer and -min. You can combine them with -exec to copy, delete, or whatever you want to do. For example:
find -maxdepth 1 -mtime +1 -type f -exec cp '{}' backup \;
Will copy all the regular files in the current directory more than 1 day old to the directory backup (assuming the directory backup exists).
Simple Example
find /path/to/folder/ -mtime 1 -exec rm {} \; // Deletes all Files modified yesterday
For more examples google for bash find time or take a look here