LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 05:17 AM   #1
grigory
Member
 
Registered: Oct 2015
Posts: 133

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, 07:05 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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, 12:03 PM   #3
grigory
Member
 
Registered: Oct 2015
Posts: 133

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 12:11 PM.
 
Old 01-14-2016, 02:43 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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, 06:56 AM   #5
grigory
Member
 
Registered: Oct 2015
Posts: 133

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, 07:10 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
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, 09:20 AM   #7
grigory
Member
 
Registered: Oct 2015
Posts: 133

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, 09:25 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

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

Original Poster
Rep: Reputation: Disabled
OK, thanks!
 
  


Reply



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 06:30 AM
LXer: What is Anacron and usage of Anacron in Linux LXer Syndicated Linux News 0 01-14-2015 02:00 AM
[SOLVED] Anacron question Ubuntu 12.04 LTS Moggertron Linux - General 1 02-01-2013 06:04 PM
Anacron email - Segmentation Fault - Ubuntu devnull10 Linux - Software 5 12-13-2010 04:54 PM
Ubuntu and Win98SE workgroup assistance. kchingx Ubuntu 2 09-29-2005 01:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:31 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
Open Source Consulting | Domain Registration