Crontab <foldername> - removed the whole crontab

Hello,

Hope you are doing great though the situation is not so good #Corona.

By mistake I ran the below command and my crontab is gone now . Could anyone please let me know what this command actually does and if possible how to recover the crontab entry.

ccs is one of my folder name .

crontab ccs

Thanks

Hi
If in the current directory where you ran this command there was an empty file with the name 'ccs',
then you probably deleted all your tasks. Just create new ones and that's it.

1 Like

Thank you .

But in my case I have a directory in that name ccs and the directory contains the files inside . I am more curious to know how it works whether it works like a redirection operator type ?

I will show better

crontab -l

#no tasks, empty

echo '*/1 * * * * /usr/bin/notify-send "*******HELLO TO EVERYONE HERE ON OUR MOON******"' >my_file
crontab my_file
crontab -l
*/1 * * * * /usr/bin/notify-send "*******HELLO TO EVERYONE HERE ON OUR MOON******"

#A message will be displayed every minute

touch another_my_file
crontab another_my_file
crontab -l

#no tasks, empty

crontab considers the current file as own that you edit or assign as here

--- Post updated at 15:01 ---

crontab /dev/null
crontab -l
#no tasks, empty
1 Like

Looks like a little bug.
crontab filename should check that filename exists and is a regular file (not a directory, device node, or other special file).

Just crontab (without arguments) should overwrite the crontab from stdin (e.g. at a terminal take the typed input until a Control-D at the beginning of the line ends it.). At a terminal a Control-C should stop it and keep the old cron table.

1 Like

Thanks. That almost answered my question. But what if I pass a directory not a file name ?
Does Linux interpret it as an empty file ?

Obviously it does so :frowning:

Once in Solaris there was a bug that a "crontab" command wiped the crontab, even if it was aborted with Control-C.
Sun fixed it soon.

BTW, I have some scripts that modify the crontab like

crontab -l | sed ... | crontab

(While older Linux cron versions require crontab - rather than just crontab .)
The standards require that it works (crontab buffers it in a temporary file).
Of course, one bug in the sed script, and it gets spoiled.

2 Likes