Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Good Morning :-), I am system administrator, one of the user wants to setup cron job and run all the time, while he log out from the server.
how could be possible.
please help me out....
Each user has their own crontab that they can use (there may be some requirement to enable crontab for users, but on CentOS, which I use, it's enabled)
crontab -e
will allow them to edit/install their own crontab, and this will execute as requested once the user logs out. See man crontab for details
The cron jobs do not require pseudo-terminal allocation to do their work, so they act indipendently from the user being logged in or not. As billymayday suggested, you have to be sure the cron daemon is running and the users are allowed to run their own crontab. If the user set a cron job at 4:00 AM, the cron daemon will do its work: run the user's job and send the standard error and the standard output to the user's mailbox, unless they have been explicitly redirected to a file.
Anyway, there is a chance the user really need to be logged in: if the cron job runs a program which requires a DISPLAY, that is a graphical application, the user must have the credentials to use an already assigned X environment. But he/she must explicitly set the DISPLAY variable into his/her job. It's not an easy task if the DISPLAY does not belong to the user itself.
Regarding the creation of a user crontab, see man crontab and man 5 crontab. The former explains the usage of crontab in general, the latter explains the format of the crontab file.
Well the user would log in by some mechanism, and will need to open a terminal session (if they log in with ssh they are probably already there). They would then type "crontab -e", enter the relevant information (see man crontab) and exit. Exiting will install the new crontab and it should run auromatically if you have cron installed on your system. I don't know what distro you are using, but on all mine, editing crontab uses vim command (vim is an editor). You can search google for vim commands - they take a bit of getting used to.
Cron will execute so long as the machine is on, whether the user is logged in or not is irrelevant. Teh user can specify which minute of which hour of which day of the week or calendar day of which month command run (it is simple to specify every 5 minutes for example). Here is a typical line from one of my crontabs
As others said, cron is about running your task at scheduled times. It's not primarily about running continuously, and independent of whether the user is logged out or in.
Maybe cron is not the solution to your user's problem. Can you describe what he/she is trying to achieve?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.