5

I am on Arch Linux and I'm trying to make a cron job that fires every minute. So I use:

$ crontab -e

And add the script in:

* * * * * Rscript /srv/shiny-system/cron/CPU.R
~
~
"/tmp/crontab.8VZ7vq" 1 line, 47 characters 

(I have no idea what that "/tmp/crontab.8VZ7vq" is!)

But it is not working - CPU.R is not running every minute. What should I do then in Arch Linux to run the cron job? I have looked into these wiki guides below but I am still lost:

Edit

I found some hints from here regarding crond.

[xxx@localhost ~]$ systemctl status crond
● crond.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)
[xxx@localhost ~]$ sudo systemctl start crond
[sudo] password for xxx: 
Failed to start crond.service: Unit crond.service failed to load: No such file or directory.

What does this mean? Where should I put this crond.service and what script should I put in it?

  • Once per minute is the finest granularity offered by crond, per crontab(5). – thrig Feb 12 '16 at 19:10
  • sorry I think I mean per minute, not per second as it seems impossible. – laukok Feb 12 '16 at 19:11
  • I can run that cron job in my Ubuntu linux but not on Arch linux that is the only problem. – laukok Feb 12 '16 at 19:12
  • Can you run the script by hand on Arch and Ubuntu both? (i.e., is it only failing when run via cron?) – Eric Renouf Feb 12 '16 at 19:16
  • are you sure that /srv/shiny-system/cron/CPU.R exists and have execute permissions ? Also as which user (root or non-root) are you trying to run this crom job ? – MelBurslan Feb 12 '16 at 19:18
6

There is no crond.service on Arch Linux. As the Arch Wiki makes perfectly clear:

There are many cron implementations, but none of them are installed by default as the base system uses systemd/Timers instead.

Consequently, if you want to use cron, you have to choose which of the many implementations you will install, and then start that specific service.

You don't just randomly type systemctl enable nonexistent.service and then wonder why it isn't running...

If you want cronie, then you install cronie and start it with:

pacman -Syu cronie
systemctl enable --now cronie.service

The Arch documentation is generally very clear; if you read the pages you linked to more carefully, you should find out what you need.

| improve this answer | |
  • Cronie doesn't seem to work. I followed Arch Wiki guide and got same problems. Although my cronie.service is running and I made sure my script name doesn't include any spaces, dots... Script won't work with cronie while it works on it's own. So either cronie package is somehow bad or Arch Wiki should be fixed. Here is my pastebin: pastebin.com/gW4tmn86 – 71GA Jun 20 '16 at 22:45
  • sudo EDITOR=nano crontab -e to use nano! – prodigerati Jul 13 '17 at 5:07
1

If I understand you right, you mean with...

How to run a 'cron' job

...scheduled events on arch Linux. That's pretty simple using systemd/Timers as a cron replacement.

Although cron is arguably the most well-known job scheduler, systemd timers can be an alternative.

Benefits

The main benefits of using timers come from each job having its own systemd service. Some of these benefits are:

  • Jobs can be easily started independently of their timers. This simplifies debugging.
  • Each job can be configured to run in a specific environment (see systemd.exec(5)).
  • Jobs can be attached to cgroups.
  • Jobs can be set up to depend on other systemd units.
  • Jobs are logged in the systemd journal for easy debugging.

...as mentioned here

If you have to use cron it is still possible and described here.


To make this answer a useful one, a minimal example for a daily automatic scheduled reboot at 01:30.

1. Create two files, one service file and one timer file. Both names (.timer and .service) have to match. F.e.:

sudo vim /usr/lib/systemd/system/scheduledReboot.service

sudo vim /usr/lib/systemd/system/scheduledReboot.timer

(The folder /usr/lib/systemd/system/... is the default folder containing all .service files just fyi)

2.1 The File scheduledReboot.service contains:

[Unit]
Description=Scheduled Reboot

[Service]
Type=simple
ExecStart=/usr/bin/systemctl --force reboot

2.2 The file scheduledReboot.timer contains:

[Unit]
Description=Reboot Scheduling.

[Timer]
OnCalendar=*-*-* 01:30:00

[Install]
WantedBy=multi-user.target
  1. And finally start the jobs:

sudo systemctl start scheduledReboot.timer

sudo systemctl enable scheduledReboot.timer

  1. Check if the job is successfully created:

sudo systemctl list-timers --all

and/or

sudo systemctl status scheduledReboot.timer

..that shows stuff like:

Trigger: Sun 2020-05-31 01:30:00 EDT; 10h left


I personally really like the systemd / .service approach since I use all my system jobs with systemctl like automatic mounting my nfs drives and so on and it works really well and efficient.

| improve this answer | |
-1

e

create a file with you crone task etc. cron.txt

cat cron.txt 0 1 * * * systemctl stop iradio; shutdown -P 0 30 23 * * * systemctl stop clock 34 23 * * * systemctl start clock

then crontab the new file

crontab cron.txt

It seems to be working now.

| improve this answer | |
  • 1
    OP has created a crontab file; their issue is that a cron daemon isn't running to read it. – jasonwryan Jul 17 '16 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.