LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-13-2016, 06:17 AM   #1
grigory
Member
 
Registered: Oct 2015
Posts: 105

Rep: Reputation: Disabled
Need some assistance with anacron in Ubuntu


Hello!

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?
 
Old 01-14-2016, 08:05 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
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.
 
Old 01-14-2016, 01:03 PM   #3
grigory
Member
 
Registered: Oct 2015
Posts: 105

Original Poster
Rep: Reputation: Disabled
Thanks for your reply!

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:

1 3 mytestscript /bin/bash /home/myname/bin/script.sh

P.S. It says "command not found" in the terminal when I go somewhere and then type my script's name. Maybe I should put it in path or something?

Last edited by grigory; 01-14-2016 at 01:11 PM.
 
Old 01-14-2016, 03:43 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Code:
/etc/anacrontab

1  3  cron.weekly /home/myname/bin/script.sh
The script will run as root. Since you use the full path in your anacrontab it does not matter where the file is located.
 
Old 01-16-2016, 07:56 AM   #5
grigory
Member
 
Registered: Oct 2015
Posts: 105

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Code:
/etc/anacrontab

1  3  cron.weekly /home/myname/bin/script.sh
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?
 
Old 01-16-2016, 08:10 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
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.
 
Old 01-16-2016, 10:20 AM   #7
grigory
Member
 
Registered: Oct 2015
Posts: 105

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
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"?
 
Old 01-16-2016, 10:25 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Sorry for the confusion, it can be mybackupscript.
 
Old 01-16-2016, 11:05 AM   #9
grigory
Member
 
Registered: Oct 2015
Posts: 105

Original Poster
Rep: Reputation: Disabled
OK, thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: What is Anacron and usage of Anacron in Linux LXer Syndicated Linux News 0 01-14-2015 07:30 AM
LXer: What is Anacron and usage of Anacron in Linux LXer Syndicated Linux News 0 01-14-2015 03:00 AM
[SOLVED] Anacron question Ubuntu 12.04 LTS Moggertron Linux - General 1 02-01-2013 07:04 PM
Anacron email - Segmentation Fault - Ubuntu devnull10 Linux - Software 5 12-13-2010 05:54 PM
Ubuntu and Win98SE workgroup assistance. kchingx Ubuntu 2 09-29-2005 02:42 AM


All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration