Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I've got Ubuntu 14.04 I try to learn about using anacron. And there're 3 things so far that I can't understand. Please explain!
1.) WHEN does the anacron command (tast) should be executed for the FIRST TIME?
Let's say today is Wednesday 2 p.m. (14:00) and I've just made a new weekly task for anacron. So when should I be expecting the first execution of it? In other words, what's the starting point here? Weekly, starting from...???
2.) Let's say I've got 3 commands. So this MUST be a script OR... I can stuff all three commands in ONE single anacron task? To be more specific, I want to stop the process, delete the file's content and then to re-start the same stopped process.
3.) Where should I put the commands for anacron? They say that in /etc/anacrontab, but there I see 3 default lines of commands that govern the cron (if I understand that correctly). Should I write my own commands in the same place just below those three?
A date stamp is written in /var/spool/anacron. Your command will run a week later with the start time based upon the delay. If you computer is running it will be 07:30 plus the delay time. If not running or sleeping and the date has passed it will run at boot/wake up plus the delay.
Your anacron job should be written beneath the existing jobs. I've never played with anacron much so not sure if all three can be on the same line. I would create a separate script.
I made a bash script and I made it by using gedit as sudo. Let's call it "script.sh". Then I made the script executable. I've already tested it. It does run, but with sudo. Inside the script I didn't put sudo. The script's attributes are:
-rwxr-xr-x
I wanna put it in /home/myname/bin/script.sh
So what about cron/anacron? Does it act as root, so it has enough privileges to run the script the way it is (as I described)?
In /etc/passwd root has /bin/bash, but in both /etc/anacrontab and /etc/crontab it's written:
SHELL=/bin/sh. Is it Okay? Or I must put /bin/bash into the anacron's command for script's execution? In other words, do I have to specifically instruct anacron to use bin/bash as an interpreter?
Could you help me with what exactly I should put into /etc/anacrontab. Say if I want my script to run daily with a 3 minute delay. Should I make it like so:
The script will run as root. Since you use the full path in your anacrontab it does not matter where the file is located.
Thanks for your reply!
So I don't have to specifically instruct anacron to use /bin/bash then? If so,okay... But one more thing though. You wrote "cron.weekly" in the command above. Some tell me to use cron.daily. What's the difference? Let's say that I want anacron to execute my script every day. So I don't understand why you wrote cron.weekly, as opposed to cron.daily?
cron.weekly is the job identifer. The name of the time stamp file saved in /var/spool/anacron. It probably should be different from the other cron.weekly jobs.
Just to confuse you a bit you could put your script in /etc/cron.weekly and it will run with the normal system weekly jobs.
cron.weekly is the job identifer. The name of the time stamp file saved in /var/spool/anacron. It probably should be different from the other cron.weekly jobs.
Just to confuse you a bit you could put your script in /etc/cron.weekly and it will run with the normal system weekly jobs.
Then why the job identifier must be either "cron.daily" or "cron.weekly". Why can't it be, say, "mybackupscript"?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.