3

I'm running a Debian server on EC2, and a few days ago my crontab definitions suddenly disappeared. Just vanished without provocation!

Any ideas what can be responsible for that? I don't suspect any unauthorized access to the server.

mba_fv
  • 56
  • 1
  • 5

4 Answers4

5

Unfortunately, it's extremely easy to lose a user crontab (and almost as easy when that user is root).

Here are a couple of examples of ways to empty one out:

crontab ''

echo $emptyvar | crontab -

crontab emptyfile

crontab -l | oops | crontab -

Where oops represents some command that is supposed to manipulate the contents output by crontab -l before replacing them using crontab. For some reason ("oops") the contents don't get passed through the pipe.

You should check your scripts and crontabs for any lines that attempt to manipulate root's crontab and make sure they're not doing something wrong.

Also, for user crontabs, when you edit one yourself always use crontab -e.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
  • 4
    Also crontab -r will remove it completely. That r is very close to the e too. I've had that awful moment once before on production. Not sure if debian warns you but HPUX doesn't. – egorgry Feb 19 '11 at 15:37
  • @egorgry: I omitted that information since the OP said the definitions disappeared rather than the file. Perhaps I should have included it. – Dennis Williamson Feb 19 '11 at 15:39
  • The crontab -r was my reason. Looking thru the history for the shell had that row.... – Kristoffer Aug 06 '13 at 19:27
2

It could be that the partition where /var is located was full.

If this is happening and /tmp is located in another partition you can edit the temporal file with crontab -e but when you finish the edition the new version can not be copied to /var/spool/cron/ and as result you obtain an empty file.

I know this is a strange case but crontab does not return any error.

1

Reading about EC2 issues on forums.aws.amazon.com. Not specifically this problem but static data disappearing after reboots. You might want to jump in to some discussions over there or contact aws support. In the mean time I'd script something to backup my crontabs to S3 or something.

egorgry
  • 2,871
  • 2
  • 23
  • 21
0

See if the crontab file actually exists in /var/spool/cron/crontab/ before you try to edit it. Is it empty or is it being created at that moment?

Has your EC2 instance rebooted?

grep -r crontab /etc/* and see if there's anything touching them.

gtirloni
  • 5,746
  • 3
  • 25
  • 52
  • the file in /var/spool/cron/crontabs/ is non-empty now, after I recreated it. It doesn't repeatedly disappear. And yes, the instance rebooted some time before the disappearance - but why would a reboot wipe out my crontab? – mba_fv Feb 19 '11 at 15:16
  • @mba_fv: Yes, a reboot may have erased your crontab, depending on your EC2 storage settings: "..if you stop or terminate the instance, the data in the instance store will be lost.", cf. the second paragraph in the [chapter about storage concepts in the docs](http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/instance-storage-concepts.html). – Axel Knauf Feb 20 '11 at 17:48