Question

I need to make a crontab to gzip a file named mh located on my desktop every 2 minutes in the same path. I tried

2 * * * * gzip home/Desktop/mh >> home/Desktop

But it is not working, any help is greatly appreciated.

Was it helpful?

Solution

There are several errors here.

  1. The gzip command should be simply gzip home/Desktop/mh. Remove the >> and everything afterwards.

  2. Your current cron will only run on the second minute of every hour. Instead you want */30 * * * * ... to run 30 times per hour.

Note that gzip is "destructive" in the sense that your original file (mh) will disappear after each gzip. That would be bad if some other process is trying to write to it continually...

If you want to keep the content of mh and just update mh.gz from it periodically, you want to do

*/30 * * * * gzip < /home/Desktop/mh > /home/Desktop/mh.gz
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top