Parisa
Parisa

Reputation: 29

Using a crontab to gzip a file

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.

Upvotes: 1

Views: 5348

Answers (1)

dg99
dg99

Reputation: 5663

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

Upvotes: 2

Related Questions