Better Than Cron Jobs
Feb 2, 2018 - Docker gives us a way to isolate processes but when it comes to cron jobs, let's run them on the Docker host when possible. How to Create a Cron Job (Scheduled Task) for Your Website or Blog by Christopher Heng, thesitewizard.com On occasion, you might come across the need to create a scheduled task for your site.
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. Today!Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.Are you new to LinuxQuestions.org? Visit the following links: If you have any problems with the registration process or your account login, please. If you need to reset your password,.Having a problem logging in?
Please visit to clear all LQ-related cookies. Introduction to Linux - A Hands on GuideThis guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration.
This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.to receive this Complete Guide absolutely free. I don't understand the question. The way to make cron jobs run as the root user is to put the job in root's crontab. There is no need to and plenty of reason NOT to do an su to root from within a cron script.To update root's crontab you of course have to be root:Become root user (requires you to know the password):su -Edit root's crontab after the su -:crontab -eThis puts you in a vi session - you make your changes then:wq! And it saves them.
You can verify they're OK by doing:cat /var/spool/cron/root(this IS the crontab for root). /etc/crontab is an alternate way of doing cron.It's better IMO to do it the way I said.
If for no other reason than because most UNIX variants don't have /etc/crontab so doing it the other way insures you're consistent across Linux/UNIX environments so you only have to remember one way.The syntax in /etc/crontab is different - it contains 'root' to tell it to run those jobs as root. The root crontab I mentioned earlier doesn't need such a field because it is named root so cron understands to run everything it contains as root.
Setting Up A Cron Job
/etc/crontab is an alternate way of doing cron.It's better IMO to do it the way I said. If for no other reason than because most UNIX variants don't have /etc/crontab so doing it the other way insures you're consistent across Linux/UNIX environments so you only have to remember one way.The syntax in /etc/crontab is different - it contains 'root' to tell it to run those jobs as root. The root crontab I mentioned earlier doesn't need such a field because it is named root so cron understands to run everything it contains as root. No worries.I try to avoid distro/variant centric ways of doing things just because I'm lazy. I'd rather remember the generic way (e.g.
/etc/init.d/ start) than the centric way (e.g. Service start for Linux) just because it keeps my little brain from getting crammed with too much.It's not always possible though. HP-UX has 'bdf' which works much better than it's 'df -k' and it doesn't have 'df -h' like Linux. I do however avoid things like HP-UX's 'll' which is just a shortcut command for 'ls -l' as 'll' only exists on HP-UX. I could create aliases or scripts on other hosts but they might not be available if I had to sit down at some foreign system. An example of that would be recent testing I did offsite at an Oracle testing facility where I had no access back to my company's servers. If the file for chkroot isn't executable for root it will give you that (even though root can override permissions).Also it's possible it IS running chkroot but something within chkroot is getting the permission denied message instead.What is the exact error you're seeing and where are you seeing it?
Fans of formula one, go for it. With its driving combining both sensations and racing strategy, F1 2018 brings an unusual depth in car games.
Do you have the line in cron redirecting to a log file?e.g. 30 3. /root/myprog.sh /root/myprog.out 2&1Would make it send output (stdout and stderr) to myprog.out. The cron log (/var/log/cron) won't give you details - it will simply show the start and return code of the job.
You have to do something like the above redirections to get detailed output from the line in cron.For even more detailed output you can put echo statements within myprog.sh at key points.e.g. Echo 'Now doing the flippity-flop routine'Also remember cron is not like a user shell. You have to be sure to give full paths for commands you're executing within the script.e.g. /usr/bin/awk instead of just awkOr you can define PATH within the script itself.P.S.
You verified this shows up in the root crontab? If you were logged in as a different user when you did crontab -e it would have created a file for that user rather than editing the one for root. Line 1 of chkrootkit would likely mean it IS running the cron job but saying it can't find the command you have in the first line of chkrootkit itself.Look at what I said about PATH earlier. Scripts that run fine at command line often do not run in cron. This is because when you login as a user you execute /etc/bashrc or /etc/profile then $HOME/.bashrc and/or $HOME/.bashprofile or $HOME/.profile.
These files build your environment. Any command you execute at the command line inherits your environment.cron on the other hand doesn't actually 'login' and it doesn't really run the full shell. Because of this you have to insure there is an environment in the shell script if you want it to run like it did from command line.
The MOST common environment item missing is the PATH variable. PATH tells it where to look for exeuctable files (binaries and scripts).So if you login and do 'echo $PATH' you'll see multiple things separated by colons (. Each of these are directories to search for desired command. If you do 'echo $PATH' it will show you what is in this variable (env shows you all of your environment).