confusion: cron jobs + boot-up manager SOLVED

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
User avatar
linx255
Level 5
Level 5
Posts: 682
Joined: Mon Mar 17, 2014 12:43 am

confusion: cron jobs + boot-up manager SOLVED

Post by linx255 »

I would like to run some cron jobs but I'm confused on a few points and also in general regarding how crontab works...
  • A) Should I enable cron in Boot-Up Manager or what's the correct way to toggle cron? I'm surprised to find it disabled, if this is what's responsible for activating cron jobs. Maybe I turned it off at some point, but I can't imagine why. But, I only recently installed Boot-Up Manager and since B.U.M. isn't installed by default and 'cron' is not in Startup Applications or /etc/xdg/autostart or /home/user/.config/autostart, therefore...

    B) How do I know cron is running? The tasks might not do anything that I can detect, or at least I don't see anything in the system monitor.

    C) Which default cron tasks do I really need and might I eliminate some of them to increase performance? I don't quite understand why ones like apt, aptitude, dpkg, ntp, and passwd are necessary, and I don't remember what was here by default. I'm not really doing anything fancy with cron so I'm a little surprised how many files are in there because it seems like at least a year ago there weren't so many.

    D) I read the crontab man page and am totally lost when it refers to the 'current crontab'. Can you explain more vividly how crontab is structured?

    E)

    Code: Select all

    crontab -e
    asks for me to select from a list of editors that I don't know how to use, which begs the question: is this command one of those dated ones or is there a good reason for not using a lay-person-friendly editor like pluma?
My crontab looks like this:

Code: Select all

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
and anacrontab:

Code: Select all

# /etc/anacrontab: configuration file for anacron

# See anacron(8) and anacrontab(5) for details.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
HOME=/root
LOGNAME=root

# These replace cron's entries
1	5	cron.daily	run-parts --report /etc/cron.daily
7	10	cron.weekly	run-parts --report /etc/cron.weekly
@monthly	15	cron.monthly	run-parts --report /etc/cron.monthly
/etc/cron.daily contains:
  • 0anacron
    apache2
    apt
    aptitude
    bsdmainutils
    chkrootkit*
    cracklib-runtime
    dpkg
    logrotate
    man-db
    ntp
    passwd
    upstart
    rkhunter*
    tripwire*
Those marked * I added myself.

Code: Select all

crontab -l
gives:
no crontab for user
Thank you very much!
Last edited by linx255 on Sun Nov 15, 2015 6:36 pm, edited 1 time in total.
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
tolkien
Level 2
Level 2
Posts: 72
Joined: Sat Nov 14, 2015 9:50 am

Re: confusion: cron jobs + boot-up manager

Post by tolkien »

A+B. cron should be activated automatically by /etc/init.d on boot. Type "service cron status" to see if you get a PID back.
To toggle cron on and off you can use "sudo service cron start" and "sudo service cron stop".
Also, cron stores logs in /var/log/syslog. To list only the relevant logs, you can use "grep CRON /var/log/syslog".

C. I am not sure... Some of the scripts seem to back up data. Anyway, they are system scripts, so I wouldn't change them unless you know what you are doing.

D. A crontab (= cron table) file is a simple text file in which shell commands are written in order to be executed periodically by the cron daemon. Every user can have a crontab, and there is also a system crontab. The user crontab files are saved in /var/spool/cron/crontabs and the system crontab in /etc/crontab.
There are two sections in a crontab file: the command itself and the frequency it needs to be executed (the system crontab also includes a user field).
For example: @daily echo hello >> ~/cron.txt
"@daily" means run the command once a day (at midnight).
"echo hello >> ~/cron.txt" is the command itself.
Read this for more information on the structure:
http://www.cyberciti.biz/faq/how-do-i-a ... unix-oses/

E. You can edit the system crontab file manually, but not the user ones because the changes would not take effect. This is why we have special commands, such as "crontab -e' and "crontab -r" to edit and remove the crontab file.
You can also place your scripts in the special directories: /etc/cron.daily, /etc/cron.hourly, etc. cron goes over these directories and execute the scripts in them. This behavior is specified in the system crontab file by the "run-parts" command, which executes scripts in a directory.

When you typed "crontab -l" your user did not have a crontab file set up, so all you received was "no crontab for user". To create one, use "crontab -e".

BTW, as for the text editor, 'nano' is simple : )
User avatar
linx255
Level 5
Level 5
Posts: 682
Joined: Mon Mar 17, 2014 12:43 am

Re: confusion: cron jobs + boot-up manager

Post by linx255 »

Excellent. :)

I have a PID for cron, so that must mean that /etc/cron.* are running.
Why then do I need both /etc/cron.* and also a crontab elsewhere?
Just multiple ways of doing the same thing I guess?
I need to read up on the linux directories, haven't gotten around to it.

However, I opine nano is too simple.
It's like one of those early 1980's word processors. :lol:
I much prefer the ability to click anywhere on a line and edit and have graphical buttons and normal menus. :lol:
Too bad pluma doesn't perform edits as nano does.
That's one of those things I'd like to see built-in to pluma / bluefish.

Tks again
- I'm running Mint 18 Mate 64-bit
- 4.15.0-34-generic x86_64
- All my bash scripts begin with #!/bin/bash
Ark987
Level 4
Level 4
Posts: 352
Joined: Tue Apr 07, 2015 4:20 am

Re: confusion: cron jobs + boot-up manager

Post by Ark987 »

As posted before, first check the status of the daemon/service, but beware of typos:

Code: Select all

service crond status
Crond controlls anacron as well, the difference between cron and anacron are:

Cron:
  • Can be used by any user on the system and is run with the user's permission/profile
  • The system must be online to be able to execute the task, if offline the schedule is missed and lost
  • It can be run at specific time, every minute if you want.
Anacron:
  • The minimum occurrence is once per day
  • Only root can create Anacron tasks and task are run as root as well
  • If a schedule is missed it will be executed in the next system boot
By default anacron is pre-configured and ready to use, the entries that you saw in /etc/anacrontab:

Code: Select all

1   5   cron.daily   run-parts --report /etc/cron.daily
7   10   cron.weekly   run-parts --report /etc/cron.weekly
@monthly   15   cron.monthly   run-parts --report /etc/cron.monthly
Reading the fist line:
  • 1 means the script will be executed every 1 day
  • 5 means the script will be executed 5 minutes after the system boot up
Basically to use cron just use crontab -e
https://en.wikipedia.org/wiki/Cron#Configuration_file

To use anacron link or save your script file in any of the default folders, the names are self explanatory:
  • /etc/cron.daily/
  • /etc/cron.hourly/
  • /etc/cron.monthly/
  • /etc/cron.weekly/
You don't want to delete any task that we not created by you, for example if you remove the logrotate job your log files will increase in size and will never be cleaned up nor rotated.
tolkien
Level 2
Level 2
Posts: 72
Joined: Sat Nov 14, 2015 9:50 am

Re: confusion: cron jobs + boot-up manager

Post by tolkien »

linx, users have their own separate crontab files probably to enable them to automate tasks without requiring root permissions. After all, you need to be root to use the /etc/cron.* directories or edit the system-wide crontab (/etc/crontab).
I also find it a bit messy though : )

Also, if you prefer a graphical text editor when editing user crontab files, I think you can modify the file "~/.selected_editor" and specify the editor of your choice.
For example for pluma:
SELECTED_EDITOR="pluma"
Post Reply

Return to “Software & Applications”