I add some job in crontab file on a server.
When I log out and the server is still on, will the job still run?
Does it matter if I create a screen or tmux session and run some shell in it and detach it before log out?
cron
is a process which deals with scheduled tasks whether you are logged in or not. It is not necessary to have a screen or tmux session running since the cron daemon will execute the scheduled tasks in separate shells.
See man cron
and man crontab
for details.
crontab -e
to read about the user crontab file andcat /etc/crontab
to read about the server-wide crontab file. From a user crontab file you can not run commands using a different user although it is possible to use sudo if passwordless commands are specified – Lambert Apr 21 '15 at 13:33/etc/crontab
is for system-wide, then where is the crontab file for a user? – Tim Apr 21 '15 at 19:42man crontab
on Ubuntu the user crontab file is located in/var/spool/cron/crontabs
. But be carefull, the manual also say that those files are not intended for direct editing. You should usecrontab -e
from the user context orcrontab -e -u username
from the root user to edit the user crontab. – Lambert Apr 21 '15 at 19:49~/.crontab
bycrontab ~/.crontab
. Is it a good suggestion? – Tim Apr 21 '15 at 19:53~/.crontab
is not a special file and not your actual crontab. It's merely a local file you may keep for backup purposes, and you can name it whatever you want, say~/crontab.txt
. You can save it to your crontab usingcrontab ~/crontab.txt
and generate it withcrontab -l > ~/crontab.txt
– MestreLion May 10 '22 at 15:04