[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: questions about cron.daily



On Sat, Apr 08, 2023 at 11:45:50AM +1200, Alex King wrote:
> See man crontab.
> 
> There are 2 ways of maintaining your crontab:
> 
> crontab [ -u user ] file
> ...
> The  first  form  of this command is used to install a new crontab from some
> named file....
> 
> I.e. you can keep a file in your home directory (or anywhere,) update it and
> install it when changed using "crontab filename".  This is especially useful
> if you keep your home directory under version control and want your crontab
> under version control as well.  But I guess hardly anyone does this.
> 

This is *exactly* what I do when I'm editing crontabs, especially on a 
remote machine. 

crontab -l

lists any crontabs for that user.

 crontab -l > crontab.old

gives you a version of the crontab that you can keep.

cp crontab.old crontab.new ; vi crontab.new ; diff crontab.old crontab.new

will allow you to add new lines / change times or whatever.

crontab crontab.new will put the new crontab in - but you've already got
the old one if you need to revert changes. If you want to be fancy, you
can do crontab.<iso8601 date> and have them sorted.

Likewise for creating systemd unit files - NEVER "just start editing over
the top" always have an example to work from and save it. You can then
commit the series to git if you want to record exact changes.

> 
> I believe it actually causes the current crontab to be copied to a temporary
> file, where is edited, then it is installed after a successful editing
> session and the temporary file is deleted.
> 

Yes,

> Like others, I've hardly ever met people who do things the first way, but it
> likely was the original way of doing things.
> 
> Thanks,
> Alex
> 
>

All the very best, as ever,

Andy 


Reply to: