Can't get cron job to run

I have followed the cronie guide here, and am trying to use a script to backup a list of my packages daily:

#!/bin/bash
pacman -Qqe > /disks/tv/package_list.txt

I've set the permissions to 755 and placed the script in /etc/cron.daily, but the script doesn't actually run daily. I've used journalctl -xb -u cronie to try and see what's going on, but it only shows since my last reboot, which was just a few hours ago. Any pointers to figure out why this isn't running daily?

My setup.

Remove the 'b'. That means only show entries since the last boot.

Is the service running?

systemctl status cronie.service

It is running and I have it enabled.

This is what I get for yesterday from journalctl -x -u cronie | grep cron.daily:

Jul 28 03:01:01 jiibus-pc anacron[22512]: Will run job `cron.daily' in 43 min.
Jul 28 03:01:01 jiibus-pc anacron[22517]: Job `cron.daily' locked by another anacron - skipping
Jul 28 03:44:01 jiibus-pc anacron[22512]: Job `cron.daily' started
Jul 28 03:44:01 jiibus-pc anacron[22512]: Job `cron.daily' terminated

Maybe you can use

It create a list after Install, Upgrade, Remove

3 Likes

That's excellent, will definitely try that. However, I'd still like to figure out what I'm doing wrong here :laughing:

locked by another anacron - why they give not the name??? :wink: :slight_smile:

This is the output of systemctl status cronie:

● cronie.service - Periodic Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/cronie.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-07-29 22:35:41 EDT; 55min ago
 Main PID: 799 (crond)
    Tasks: 1 (limit: 4915)
   Memory: 9.8M
   CGroup: /system.slice/cronie.service
           └─799 /usr/bin/crond -n

Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT ((process:16087): GLib-GIO-CRITICAL **: 23:00:02.036: g_file_get_path: assertion 'G_IS_FILE (file)' failed)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT ()
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (** (process:16087): CRITICAL **: 23:00:02.036: tee_jee_file_system_path_combine: assertion 'path1 != NULL' failed)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT ()
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (** (process:16087): CRITICAL **: 23:00:02.036: tee_jee_file_system_dir_exists: assertion 'dir_path != NULL' failed)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (Daily snapshots are enabled)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (Last daily snapshot is 22 hours old)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (------------------------------------------------------------------------------)
Jul 29 23:01:01 jiibus-pc CROND[16622]: (root) CMD (run-parts /etc/cron.hourly)
Jul 29 23:01:01 jiibus-pc CROND[16623]: (root) CMD (run-parts /etc/cron.hourly #Runs a cron job script every hour)

Sorry I'm a bit dense at times lol, are you hinting at the root of my issue?

Wrong shebang, bash does not reside in /bin edit: see Can't get cron job to run below.

$ which bash
/usr/bin/bash

If unsure or in need of greater portability, you're better of using

#!/usr/bin/env bash

Actually it does.
/bin is a symlink to /usr/bin. :slight_smile:

1 Like

Damn, you're right. Did not see that symlink.

Post output of:

sudo crontab -l

crontab -l

Not at home right now, but I ran non-sudo last night trying troubleshoot and it was empty.

There's your problem.

man crontab

It was my understanding that cronie takes care of this, as I followed the guide I linked in OP. Am I mistaken on this?

You still have to tell cron/cronie/anacron/ etc. what to do and when to do it. That's what the crontab is for.

You can also search this forum for systemd-timers.

So is the cronie guide I linked incorrect? Or is there an implicit understanding that crontab has to also be used? As it makes no mention of using a crontab and says cronie gets its schedule and where to look from the mycronjobs file.

I didn't previously look at the tutorial. But looking at your cronie status output, it appears that you have conflicting cron entries...

Jul 29 23:01:01 jiibus-pc CROND[16622]: (root) CMD (run-parts /etc/cron.hourly)
Jul 29 23:01:01 jiibus-pc CROND[16623]: (root) CMD (run-parts /etc/cron.hourly #Runs a cron job script every hour)

Is the second entry from that tutorial?

Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (Daily snapshots are enabled)
Jul 29 23:00:02 jiibus-pc CROND[16086]: (root) CMDOUT (Last daily snapshot is 22 hours old)

Are you using timeshift? It installs it's own schedule.

Cronie has a 0hourly file that seems to be necessary which points to looking in cron.hourly. I'll try renaming it so it gets ignored. But would conflicting hourly schedules prevent a daily schedule from running?

So I identified why my script won't run. I was under the impression they needed to have a .sh extension, but clearly the guide I linked says otherwise.

1 Like

Forum kindly sponsored by