user3782645
user3782645

Reputation:

Linux cron job overwrite file

In case of cron job that creates an archive with a constant name will the archive be replaced with new one on the next cron job or terminated as the file with this name is already exists?

Upvotes: 1

Views: 2208

Answers (2)

cn0047
cn0047

Reputation: 17071

Cron just run your command, so it's up to you how this command may look. For example:

0 8 * * * rm -rf arc.zip && zip -r arc.zip /tmp

This cron runs every day at 8am and performs next steps:

  1. remove file arc.zip
  2. create new archive arc.zip from /tmp directory

Upvotes: 1

Mureinik
Mureinik

Reputation: 311498

There's no magic in cron - it just runs a program at a given timing. If that program has the logic to check if the archive exists, it will still have it when run via as a cron job. If it just overwrites the archive, it will continue doing so when run as a cron jbo.

Upvotes: 2

Related Questions