Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
0
votes
2
answers
1614
views
Timeshift weekly cron emails
I recently installed timeshift and set it to backup weekly. However, when I looked in /etc/cron.d, I only found timeshift-hourly which ran: 0 * * * * root timeshift --check --scripted which appears to check with timeshift if a backup is schedule and if so, do it. However, I would like to set a cron...
I recently installed timeshift and set it to backup weekly. However, when I looked in /etc/cron.d, I only found timeshift-hourly which ran:
0 * * * * root timeshift --check --scripted
which appears to check with timeshift if a backup is schedule and if so, do it.
However, I would like to set a cron email for every time I backup and I'm guessing that if I set if for timeshift-hourly, then I will get an email every time that it checks every hour. How would I be able to set a cron email for every time that timeshift does a backup and not every time it checks to see if it's time to backup?
Paradox
(794 rep)
Nov 23, 2019, 08:15 PM
• Last activity: Jun 26, 2024, 12:43 PM
0
votes
1
answers
554
views
Anacron doesn't appear to run anything on Debian, but why?
I have an odd problem with my Debian server. Up until a few weeks ago, anacron was running my cron jobs fine and I can see I have backups from then so it was running stuff. Then it appears to have just stopped running cron tasks in /etc/cron.daily/weekly/monthly. The logs, however, don't show any is...
I have an odd problem with my Debian server. Up until a few weeks ago, anacron was running my cron jobs fine and I can see I have backups from then so it was running stuff. Then it appears to have just stopped running cron tasks in /etc/cron.daily/weekly/monthly. The logs, however, don't show any issues. Here's my recent anacron log:
Nov 27 22:30:58 localhost anacron: Anacron 2.3 started on 2023-11-27
Nov 27 22:30:58 localhost anacron: Normal exit (0 jobs run)
Nov 27 22:30:58 localhost systemd: anacron.service: Deactivated successfully.
Nov 27 23:33:19 localhost systemd: Started anacron.service - Run anacron jobs.
Nov 27 23:33:19 localhost anacron: Anacron 2.3 started on 2023-11-27
Nov 27 23:33:19 localhost anacron: Normal exit (0 jobs run)
Nov 27 23:33:19 localhost systemd: anacron.service: Deactivated successfully.
Nov 28 07:34:01 localhost systemd: Started anacron.service - Run anacron jobs.
Nov 28 07:34:01 localhost anacron: Anacron 2.3 started on 2023-11-28
Nov 28 07:34:01 localhost anacron: Will run job `cron.daily' in 5 min.
Nov 28 07:34:01 localhost anacron: Jobs will be executed sequentially
Nov 28 07:39:01 localhost anacron: Job `cron.daily' started
Nov 28 07:39:02 localhost anacron: Updated timestamp for job `cron.daily' to 2023-11-28
Nov 28 07:39:03 localhost anacron: Job `cron.daily' terminated
Nov 28 07:39:03 localhost anacron: Normal exit (1 job run)
Nov 28 07:39:03 localhost systemd: anacron.service: Killing process 2240176 (ConfigServer Ve) with signal SIGKILL.
Nov 28 07:39:03 localhost systemd: anacron.service: Killing process 2240182 (sleep) with signal SIGKILL.
Nov 28 07:39:03 localhost systemd: anacron.service: Deactivated successfully.
Nov 28 08:30:42 localhost systemd: Started anacron.service - Run anacron jobs.
Nov 28 08:30:42 localhost anacron: Anacron 2.3 started on 2023-11-28
Nov 28 08:30:42 localhost anacron: Normal exit (0 jobs run)
It seems to claim that the cron.daily
(as well as weekly/monthly, further back) are running fine and exiting normally. But no backups are being made, and no emails are being sent to me (I setup a test script that should always print output and therefore generate an email). I can't for the life of my figure out why anacron apparently isn't doing anything, and isn't logging any errors.
I don't *remember* doing anything back a few weeks ago that could've caused this. Here's my /etc/anacrontab:
# /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
`
What can I do to debug this and figure out what's wrong? My OS is Debian 12.1.
Jez
(1026 rep)
Nov 28, 2023, 09:27 AM
• Last activity: Nov 28, 2023, 09:47 AM
0
votes
0
answers
128
views
anacron not running weekly scripts
/etc/anacrontab: ``` # /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.da...
/etc/anacrontab:
# /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.d/anacron:
# /etc/cron.d/anacron: crontab entries for the anacron package
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
30 7-23 * * * root [ -x /etc/init.d/anacron ] && if [ ! -d /run/systemd/system ]; then /usr/sbin/invoke-rc.d anacron start >/dev/null; fi
This suggests cron does not execute anacron, but is left for systemd to handle, correct? Can't see any relevant systemd timers for it though:
$ systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Sun 2023-10-29 11:36:44 CET 17min Sun 2023-10-29 10:03:38 CET 1h 15min ago fwupd-refresh.timer fwupd-refresh.service
Sun 2023-10-29 17:27:57 CET 6h Sat 2023-10-28 18:27:57 CEST 17h ago etckeeper.timer etckeeper.service
Sun 2023-10-29 17:27:57 CET 6h Sat 2023-10-28 18:27:57 CEST 17h ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
Sun 2023-10-29 18:07:00 CET 6h Sun 2023-10-29 09:22:36 CET 1h 56min ago apt-daily.timer apt-daily.service
Mon 2023-10-30 00:00:00 CET 12h Sun 2023-10-29 00:00:01 CEST 12h ago apt-show-versions.timer apt-show-versions.service
Mon 2023-10-30 00:00:00 CET 12h Sun 2023-10-29 00:00:01 CEST 12h ago dpkg-db-backup.timer dpkg-db-backup.service
Mon 2023-10-30 00:00:00 CET 12h Sun 2023-10-29 00:00:01 CEST 12h ago logrotate.timer logrotate.service
Mon 2023-10-30 01:29:34 CET 14h Mon 2023-10-23 08:14:40 CEST - fstrim.timer fstrim.service
Mon 2023-10-30 06:22:39 CET 19h Sun 2023-10-29 10:19:49 CET 59min ago man-db.timer man-db.service
Mon 2023-10-30 06:25:00 CET 19h Sun 2023-10-29 06:25:01 CET 4h 54min ago ntpsec-rotate-stats.timer ntpsec-rotate-stats.service
Mon 2023-10-30 06:46:54 CET 19h Sun 2023-10-29 06:25:35 CET 4h 53min ago apt-daily-upgrade.timer apt-daily-upgrade.service
Sun 2023-11-05 03:10:25 CET 6 days Sun 2023-10-29 03:10:49 CET 8h ago e2scrub_all.timer e2scrub_all.service
Running sudo anacron -n
to trigger execution.
/var/log/cron.log after the run:
2023-10-25T16:46:45.570141+03:00 hostname anacron: Anacron 2.3 started on 2023-10-25
2023-10-25T16:46:45.578029+03:00 hostname anacron: Will run job `cron.daily'
2023-10-25T16:46:45.578146+03:00 hostname anacron: Will run job `cron.monthly'
2023-10-25T16:46:45.578220+03:00 hostname anacron: Jobs will be executed sequentially
2023-10-25T16:46:45.578716+03:00 hostname anacron: Job `cron.daily' started
2023-10-25T16:46:45.583688+03:00 hostname anacron: Updated timestamp for job `cron.daily' to 2023-10-25
2023-10-25T16:47:23.041584+03:00 hostname anacron: Job `cron.daily' terminated (mailing output)
2023-10-25T16:47:23.042011+03:00 hostname anacron: Job `cron.monthly' started
2023-10-25T16:47:23.047447+03:00 hostname anacron: Updated timestamp for job `cron.monthly' to 2023-10-25
2023-10-25T16:47:23.047590+03:00 hostname anacron: Job `cron.monthly' terminated
2023-10-25T16:47:23.055468+03:00 hostname anacron: Tried to mail output of job `cron.daily', but mailer process (/usr/sbin/sendmail) exited with status 78
2023-10-25T16:47:23.055626+03:00 hostname anacron: Normal exit (2 jobs run)
What gives, why weeklies aren't ran?
---
Edit: dailies are not executed either. created hosts-block-update-daily
in /etc/cron.daily
with
#!/usr/bin/env bash
echo "start @ $(date)" >> /home/mylocaluser/hosts-update-daily.log
and nothing is logged. They're only executed if anacron is ran manually as discussed in comments below.
laur
(790 rep)
Oct 25, 2023, 01:55 PM
• Last activity: Oct 29, 2023, 10:21 AM
1
votes
2
answers
383
views
Anacron kills children of my task
I wanted to set up an `anacron` task to run a `backintime` backup once a day (Ubuntu 20.04.3 LTS). If you schedule this using the `backintime` GUI, the normal crontab is being used, but for my use case this is not suitable: I usually have my computer on standby when I'm not using it, so the cronjob...
I wanted to set up an
anacron
task to run a backintime
backup once a day (Ubuntu 20.04.3 LTS). If you schedule this using the backintime
GUI, the normal crontab is being used, but for my use case this is not suitable: I usually have my computer on standby when I'm not using it, so the cronjob would just be discarded if I don't have the computer running at that exact scheduled time. What I did instead was create a script in the cron.daily
directory, so that anacron
takes care of it, which also supports delayed execution in case of standby or the computer being shut down for some time. I added the following command:
sudo -i -u samuel /usr/bin/nice -n19 /usr/bin/ionice -c2 -n7 /usr/bin/backintime backup-job >/dev/null
This is exactly what backintime
adds to the crontab, so I was sure it would work just fine when using anacron
. But that's not the case: The job is started just fine, but the backup never finishes. The syslog output is the following:
backintime (samuel/1): INFO: Lock
backintime (samuel/1): WARNING: Inhibit Suspend failed.
backintime (samuel/1): INFO: mount ssh: [...]
backintime (samuel/1): INFO: Take a new snapshot. Profile: 1 Main profile
backintime (samuel/1): INFO: Call rsync to take the snapshot
[... around 10 seconds later ...]
anacron: Job `cron.daily' terminated (mailing output)
anacron: anacron: Can't find sendmail at /usr/sbin/sendmail, not mailing output
anacron: Can't find sendmail at /usr/sbin/sendmail, not mailing output
systemd: anacron.service: Killing process 7920 (python3) with signal SIGKILL.
anacron: Normal exit (1 job run)
systemd: anacron.service: Killing process 7958 (ssh-agent) with signal SIGKILL.
systemd: anacron.service: Killing process 8107 (ssh) with signal SIGKILL.
systemd: anacron.service: Killing process 8109 (sshfs) with signal SIGKILL.
systemd: anacron.service: Killing process 8112 (python3) with signal SIGKILL.
systemd: anacron.service: Killing process 8126 (rsync) with signal SIGKILL.
systemd: anacron.service: Killing process 8127 (ssh) with signal SIGKILL.
systemd: anacron.service: Killing process 8123 (QXcbEventQueue) with signal SIGKILL.
systemd: anacron.service: Succeeded.
I find this situation rather weird, because why would anacron deliberately kill my processes? So what happens, as far as I interpret it, is that the command I'm executing in my backup script exits rather quickly, as its only task is to spin off some worker processes like python, ssh, rsync etc, and once they're running in the background, the launcher quits. So far so good, but anacron
apparently thinks it's its duty to kill off all descendants of the original backup script once the script is done. But how can I prevent it from doing so? Do I really need to manually find out the descendant PIDs and wait for all of them to be done, before exiting the backup script?
I haven't found any info on this behavior online, so I would be glad if someone had any advice on how to proceed here.
Masrepus
(31 rep)
Jan 14, 2022, 10:27 AM
• Last activity: Jul 30, 2023, 09:34 AM
0
votes
1
answers
127
views
cronjob: run script_A on boot/wake, then every 5 mins after that, run script_B on each of the 4 mins in between (so *not* just modulo-5 clock-minutes)
So I'd like to set up a cronjob in a very specific way: - run script_A on boot/wake - then every 5 minutes after, relative to that boot/wake (so *not* just modulo-5 clock-minutes) - run script_B on each of the 4 minutes *in between* (ie the minutes when script_A does *not* run) I'm really inexperien...
So I'd like to set up a cronjob in a very specific way:
- run script_A on boot/wake
- then every 5 minutes after, relative to that boot/wake (so *not* just modulo-5 clock-minutes)
- run script_B on each of the 4 minutes *in between* (ie the minutes when script_A does *not* run)
I'm really inexperienced in this whole thing,
so I'm looking for advice on what to *start* digging into first...
---
cron
itself (or maybe it's technically anacron
I'm using?) seems quite limited,
and the best it can do is apparently
*/5 * * * * /home/username/script_A.sh
---
fcron
seems a bit more powerful/flexible, including some syntax for:
@ 5 /home/username/script_A.sh
which seems to get the part "every 5 minutes starting relative to *boot/wake*, not just modulo clock-minutes"
[... although I note stackexchange doesn't *have* fcron
as an available tag, so that's maybe not a good sign...]
---
Still no clue how to handle "script_B on each of the 4 minutes *in between* script_A", though.
---
What are systemd timers like?
From a *very* superficial first glance, they look kinda boiler-plate-y verbose...?
But maybe they *do* have the power/flexibility I'm looking for...?
---
Is there anything else I should look into?
---
---
(
I'm on opensuse tumbleweed, so like,
I know for instance if I *do* go with fcron
it's gonna take a *little* work to make sure I've *really* got it installed *properly*
because I have to do so manually.
(
ie, I *did* install it from the github already,
but I'm pretty sure there's at least one or two tricky bits I need to track down to actually get it *correctly* integrated into my system.
)
What I *do* have in my package manager's repos is:
$zypper info cron cronie cronie-anacron kcron
#=>
Loading repository data...
Reading installed packages...
Information for package cron:
-----------------------------
Repository : Main Repository (OSS)
Name : cron
Version : 4.2-91.3
Arch : x86_64
Vendor : openSUSE
Installed Size : 181 B
Installed : Yes (automatically)
Status : up-to-date
Source package : cronie-1.6.1-91.3.src
Upstream URL : https://github.com/cronie-crond/cronie
Summary : Auxiliary package
Description :
Auxiliary package, needed for proper update from vixie-cron 4.1 to cronie 1.4.4
Information for package cronie:
-------------------------------
Repository : Main Repository (OSS)
Name : cronie
Version : 1.6.1-91.3
Arch : x86_64
Vendor : openSUSE
Installed Size : 310.2 KiB
Installed : Yes (automatically)
Status : up-to-date
Source package : cronie-1.6.1-91.3.src
Upstream URL : https://github.com/cronie-crond/cronie
Summary : Cron Daemon
Description :
cron automatically starts programs at specific times. Add new entries
with "crontab -e". (See "man 5 crontab" and "man 1 crontab" for
documentation.)
Under /etc, find the directories cron.hourly, cron.daily, cron.weekly,
and cron.monthly. Scripts and programs that are located there are
started automatically.
Information for package cronie-anacron:
---------------------------------------
Repository : Main Repository (OSS)
Name : cronie-anacron
Version : 1.6.1-91.3
Arch : x86_64
Vendor : openSUSE
Installed Size : 43.6 KiB
Installed : Yes
Status : up-to-date
Source package : cronie-1.6.1-91.3.src
Upstream URL : https://github.com/cronie-crond/cronie
Summary : Utility for running regular jobs
Description :
Anacron becames part of cronie. Anacron is used only for running regular jobs.
The default settings execute regular jobs by anacron, however this could be
overloaded in settings.
Information for package kcron:
------------------------------
Repository : Main Repository (OSS)
Name : kcron
Version : 23.04.3-1.1
Arch : x86_64
Vendor : openSUSE
Installed Size : 410.8 KiB
Installed : No
Status : not installed
Source package : kcron-23.04.3-1.1.src
Upstream URL : https://www.kde.org
Summary : Cron job configuration tool
Description :
KCron allows you to change your cron jobs setup.
(plus whatever might be in https://software.opensuse.org/search?baseproject=ALL&q=cron and I just don't know what to search for)
)
dwawlyn
(23 rep)
Jul 25, 2023, 07:46 PM
• Last activity: Jul 25, 2023, 08:29 PM
0
votes
1
answers
85
views
`cronnext` reports `nextstring` for every-minute cronjob as beginning of the *current* minute, ie in the *past*. Normal?
So I'm seeing this weird thing (or at least, weird to me, with my tiny amount of experience). `cronnext` tells me the `nextstring` for an every-minute cronjob is the *beginning* of the *current* minute, ie in the *past*. eg, if I run `cronnext` at `02:11:27`, it says: `nextstring: Tue Jul 25 02:11:0...
So I'm seeing this weird thing (or at least, weird to me, with my tiny amount of experience).
cronnext
tells me the nextstring
for an every-minute cronjob is the *beginning* of the *current* minute,
ie in the *past*.
eg, if I run cronnext
at 02:11:27
,
it says:
nextstring: Tue Jul 25 02:11:00 2023
(
rather than (as I'd naively expect):
nextstring: Tue Jul 25 02:12:00 2023
)
Is this normal, or...?
Cuz I couldn't find anything about it in any of the manpages,
and I haven't been able to google anything up with the terms that I've been able to think of...
I added the anacron
tag too,
cuz I *do* have it installed,
although I never used it directly,
so I don't know if it's relevant.
(
$sudo cronnext -c
#=>
- user: "username"
crontab: /var/spool/cron/tabs/username
system: 0
entries:
- user: username
cmd: "/home/username/my_script.sh"
flags: 0x0F
flagnames: MIN_STAR|HR_STAR|DOM_STAR|DOW_STAR
delay: 0
next: 1690276260
nextstring: Tue Jul 25 02:11:00 2023
next: 1690276260
)
(
I've already tracked down and fixed the bug I was originally trying to fix when I came across this,
so it turned out to just be a red-herring on that particular issue,
but I decided I still want to ask about it, cuz it still seems *weird* to me.
)
dwawlyn
(23 rep)
Jul 25, 2023, 03:39 PM
• Last activity: Jul 25, 2023, 07:33 PM
2
votes
1
answers
1839
views
cron vs. anacron
I've got a pretty good handle on how cron/anacron work on linux. My question is this: 1. anacron runs at login, and checks if it's been more than a day since the scripts in `/etc/cron.daily` have run 2. anacron runs scripts in `/etc/cron.daily`, and updates the timestamp in `/var/spool/anacron/cron....
I've got a pretty good handle on how cron/anacron work on linux. My question is this:
1. anacron runs at login, and checks if it's been more than a day since the scripts in
/etc/cron.daily
have run
2. anacron runs scripts in /etc/cron.daily
, and updates the timestamp in /var/spool/anacron/cron.daily
3. anacron exits
4. computer stays on for more than 24 hours
5. cron runs and detects a time match for cron.daily
6. cron does nothing since test -x anacrontab" == True
If my computer runs for more than 24 hours, how does cron run the scripts in cron.daily (This is a Debian based distro)?
the default /etc/crontab
(which is running every minute) tests for the presence (or more precisely, the -x bit) of /usr/bin/anacron
, and ignores the /etc/cron.daily
folder if it finds it, but it doesn't seem to restart anacron to do the work.
**EDIT:**
So cron DOES start anacron from the /etc/cron.d
folder, but only if the computer is on and logged in at 7:30 am every day. After doing a little spreadsheet kung-fu, I've come to the conclusion that the scripts in /etc/cron.daily
will run anywhere between 1 minute and 31.5 hours apart.
Ex:
Scenario 1:
- log in at 11:59 pm on 5/23/2021
- assuming the anacron timestamp for /etc/cron.daily
is older than 5/23/2021, anacron runs all the scrips in /etc/cron.daily
and updates the timestamp to 5/23/2021
- log out
- log back in at 12:00 am on 5/24/2021
- anacron sees that the last run was 5/23/2021, and it is now 5/24/2021, so anacron runs all the scripts in /etc/cron.daily
- elapsed time between runs: 1 minute
Scenario 2:
- log in at 12:00 am on 5/23/2021
- assuming the anacron timestamp for /etc/cron.daily
is older than 5/23/2021, anacron runs all the scrips in /etc/cron.daily
and updates the timestamp to 5/23/2021
- computer stays on and logged in until 7:30 am on 5/23/2021
- cron runs anacron from its crontab file in /etc/cron.d
- since the timestamp is 5/23/2021, nothing happens
- computer stays on and logged in until 7:30 am on 5/24/2021
- cron runs anacron from its crontab file in /etc/cron.d
- anacron sees that the last run was 5/23/2021, and it is now 5/24/2021, so anacron runs all the scripts in /etc/cron.daily
- elapsed time between runs: 31.5 hours
cyclopticnerve
(21 rep)
May 26, 2021, 07:19 PM
• Last activity: Jun 24, 2023, 09:42 PM
0
votes
1
answers
140
views
what is the syntax of jobs.deny?
from [man](https://linux.die.net/man/4/crontabs) it said > The execution of files can be allowed or denied by creating file jobs.allow or jobs.deny which worked similar as other allow/deny config files But the example has something like `0logwatch`, what is the `0` means here? where can I find the e...
from [man](https://linux.die.net/man/4/crontabs) it said
> The execution of files can be allowed or denied by creating file jobs.allow or jobs.deny which worked similar as other allow/deny config files
But the example has something like
0logwatch
, what is the 0
means here? where can I find the exact man page of the syntax?
Wang
(1395 rep)
Dec 2, 2022, 03:31 PM
• Last activity: Dec 2, 2022, 03:56 PM
0
votes
2
answers
273
views
Backup fails when sudo runs rclone during an anacron job
I have created a simple backup script that creates .tar.gz of all my important folders and upload it to Google Drive using **rclone**. Everything works perfectly fine when I run the script manually. But it seems to be failing when anacron runs it. I use ```anacron -fnd``` to run anacron right away t...
I have created a simple backup script that creates .tar.gz of all my important folders and upload it to Google Drive using **rclone**.
Everything works perfectly fine when I run the script manually. But it seems to be failing when anacron runs it.
I use
2022/11/28 23:58:03 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
2022/11/28 23:58:03 Failed to create file system for "linuxbackuprclone:Linux-Backup": didn't find section in config file
linuxbackuprclone is the name of my remote in rclone.
Linux-Backup is the name of the folder in Google Drive.
Here is my backup script, it's called **backup**, located at **/home/paramv/Bash-Script**, and is named backup
Any help will be highly appreciated.
-fnd
to run anacron right away to test if everything is running correctly.
Following are the error I get in my log file 2022/11/28 23:58:03 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
2022/11/28 23:58:03 Failed to create file system for "linuxbackuprclone:Linux-Backup": didn't find section in config file
linuxbackuprclone is the name of my remote in rclone.
Linux-Backup is the name of the folder in Google Drive.
Here is my backup script, it's called **backup**, located at **/home/paramv/Bash-Script**, and is named backup
#!/bin/bash
set -e
backupDirPath="/home/paramv/Linux-Backup"
if [ ! -d $backupDirPath ]; then
mkdir $backupDirPath
fi
if [ ! -d "/home/paramv/Bash-Script/Backup-Log" ]; then
mkdir Backup-Log
fi
# Create a log file named after the date the backup was created
logFile="/home/paramv/Bash-Script/Backup-Log/$(date).log"
logFile=${logFile// /_}
touch $logFile
# Create tar of dirs to backup
echo "Creating backup.tar.gz" >> $logFile
# sudo tar -zcf /home/paramv/Linux-Backup/backup.tar.gz -P /home/paramv/Documents/ &>> $logFile
if [ $? != 0 ]; then
echo "Failed to create backup.tar.gz. Error code = $?" &>> $logFile
exit 1
else
echo "Completed creating backup.tar.gz" >> $logFile
fi
# Upload local backup file to the cloud
echo "Uploading backup.tar.gz to Google Drive" >> $logFile
/usr/bin/rclone copy --update --transfers 30 --checkers 8 --contimeout 60s --timeout 300s --retries 3 --low-level-retries 10 "/home/paramv/Linux-Backup/backup.tar.gz" "linuxbackuprclone:Linux-Backup" &>> $logFile
if [ $? != 0 ]; then
echo "Failed to upload backup.tar.gz to Google Drive. Error code = $?" &>> $logFile
exit 1
else
echo "Uploaded backup.tar.gz to Google Drive" >> $logFile
fi
exit
Following is my anacron script located at **/etc/cron.weekly**, and is named prsnlbackup
#!/bin/sh
set -e
exec /home/paramv/Bash-Script/backup
exit
Following is the output of running config
.
Current remotes:
Name Type
==== ====
linuxbackuprclone drive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q>
This is what my **rclone.conf** looks like. It is located at **/home/paramv/.config/rclone**
[linuxbackuprclone]
type = drive
scope = drive
token = {"omitted to make it readable"}
team_drive =
I am running Ubuntu 22.04.1 LTS. Any help will be highly appreciated.
pvs
(1 rep)
Nov 28, 2022, 06:39 PM
• Last activity: Nov 30, 2022, 06:46 AM
1
votes
1
answers
122
views
This cron script was missed by shutdown
Is there a way to setup cron (or any other scheduler, like anacron) to run such that it checks immediately after I resume working on my laptop (e.g. after suspension or shutdown) whether it has executed a certain script that was scheduled while my laptop was inactive? The reason for this is that I f...
Is there a way to setup cron (or any other scheduler, like anacron) to run such that it checks immediately after I resume working on my laptop (e.g. after suspension or shutdown) whether it has executed a certain script that was scheduled while my laptop was inactive?
The reason for this is that I frequently do things like suspend my laptop or shut it down and in both cases cron obviously doesn't run. When I then return to normal operation the missed commands aren't executed.
------------
I know there is the tool called anacron for machines that aren't running continuously, which therefore periodically checks whether scheduled scripts were run, but the problem with that is that:
- there is a time interval between checking whether scripts were run and one of the use cases for me is to change my screen color at a certain time in the evening; after starting my laptop later in the evening I'd only be willing to wait at most half a second (!) until the color change is carried out and I guess a scheduler with a time period of half a second is probably inducing a bit of unnecessary load on my system (if such rapid checks are even possible)
- for anacron the waiting period is days which rules out any tweaks with anacron :(
Running rtcwake is also not an option: It would be way too cumbersome to pad each script with more code to potentially wake the entire system just to do simple plumbing stuff like to change my screen color.
user7088941
(111 rep)
Oct 2, 2022, 05:34 AM
• Last activity: Oct 3, 2022, 09:46 AM
1
votes
2
answers
1205
views
Why can I ping to 8.8.8.8 or openDNS server but no other websites?
I am using USB wired modem to connect internet(over eth0 interface) in Debian Bullseye (*uname -a >>* **Linux styx 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux**). Sometimes, my ethernet interface suddenly stops. Interestingly : 1. I can ping to gateway(success), 2. I can pin...
I am using USB wired modem to connect internet(over eth0 interface) in Debian Bullseye (*uname -a >>* **Linux styx 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64 GNU/Linux**). Sometimes, my ethernet interface suddenly stops. Interestingly :
1. I can ping to gateway(success),
2. I can ping to 8.8.8.8(success),
3. Interface seems **up** (I checked **ip addr show**)
4. I restart interface by **ifdown** first, and then by **ifup**, nothing happened, ethernet interface name changed from eth0 to enxMACADDRESS, but still no internet connection.
5. I checked the output of **ip route**, it was the same configuration as with eth0 when it was working.
I checked the previous question&answers (such as no connection , etc.). I can ping to 8.8.8.8 but there is not internet(No ping to other IPs, such as openDNS's servers).
There is no error about interface and it is up. Only I have to unplug and replug USB cable and then connection re-established.
[ EDIT BEGIN ]
After comments and answer, I checked the /var/log/syslog as Felicia stated as answer and I found that :
Feb 21 11:40:30 localhost kernel: [ 3936.163162] usb-storage 3-5.4:1.2: USB Mass Storage device detected
Feb 21 11:40:30 localhost kernel: [ 3936.167079] scsi host10: usb-storage 3-5.4:1.2
Feb 21 11:40:30 localhost mtp-probe: checking bus 3, device 18: "/sys/devices/pci0000:00/0000:00:1d.7/usb3/3-5/3-5.x"
Feb 21 11:40:30 localhost mtp-probe: bus: 3, device: 18 was not an MTP device
Feb 21 11:40:30 localhost systemd-udevd: Using default interface naming scheme 'v247'.
Feb 21 11:40:30 localhost systemd-udevd: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.
Feb 21 11:40:30 localhost kernel: [ 3936.225574] cdc_ether 3-5.x:1.0 enxXXXXXXXXXXXX: renamed from eth0
Feb 21 11:40:30 localhost mtp-probe: checking bus 3, device 18: "/sys/devices/pci0000:00/0000:00:1d.7/usb3/3-5/3-5.x"
Feb 21 11:40:30 localhost mtp-probe: bus: 3, device: 18 was not an MTP device
Feb 21 11:40:30 localhost systemd-udevd: Using default interface naming scheme 'v247'.
Feb 21 11:40:30 localhost systemd-udevd: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.
Feb 21 11:40:30 localhost systemd[1] : Found device 1024.
Feb 21 11:40:30 localhost systemd[1] : Started ifup for enxXXXXXXXXXXXX.
Feb 21 11:40:30 localhost dhclient: Internet Systems Consortium DHCP Client 4.4.1
Feb 21 11:40:30 localhost sh: Internet Systems Consortium DHCP Client 4.4.1
Feb 21 11:40:30 localhost dhclient: Copyright 2004-2018 Internet Systems Consortium.
Feb 21 11:40:30 localhost sh: Copyright 2004-2018 Internet Systems Consortium.
Feb 21 11:40:30 localhost dhclient: All rights reserved.
Feb 21 11:40:30 localhost dhclient: For info, please visit https://www.isc.org/software/dhcp/
Feb 21 11:40:30 localhost sh: All rights reserved.
Feb 21 11:40:30 localhost sh: For info, please visit https://www.isc.org/software/dhcp/
Feb 21 11:40:30 localhost dhclient:
Feb 21 11:40:30 localhost dhclient: Listening on LPF/enxXXXXXXXXXXXX/X:X:X:X:X:X
Feb 21 11:40:30 localhost sh: Listening on LPF/enxXXXXXXXXXXXX/X:X:X:X:X:X
Feb 21 11:40:30 localhost sh: Sending on LPF/enxXXXXXXXXXXXX/X:X:X:X:X:X
Feb 21 11:40:30 localhost sh: Sending on Socket/fallback
Feb 21 11:40:30 localhost sh: DHCPREQUEST for 192.168.x.100 on enxXXXXXXXXXXXX to 255.255.255.255 port 67
Feb 21 11:40:30 localhost dhclient: Sending on LPF/enxXXXXXXXXXXXX/X:X:X:X:X:X
Feb 21 11:40:30 localhost dhclient: Sending on Socket/fallback
Feb 21 11:40:30 localhost dhclient: DHCPREQUEST for 192.168.9.100 on enxXXXXXXXXXXXX to 255.255.255.255 port 67
Feb 21 11:40:30 localhost dhclient: DHCPNAK from 192.168.x.1
Feb 21 11:40:30 localhost sh: DHCPNAK from 192.168.x.1
Feb 21 11:40:30 localhost avahi-autoipd(enxXXXXXXXXXXXX): Found user 'avahi-autoipd' (UID 108) and group 'avahi-autoipd' (GID 116).
Feb 21 11:40:30 localhost avahi-autoipd(enxXXXXXXXXXXXX): Successfully called chroot().
Feb 21 11:40:30 localhost avahi-autoipd(enxXXXXXXXXXXXX): Successfully dropped root privileges.
Feb 21 11:40:30 localhost avahi-autoipd(enxXXXXXXXXXXXX): Starting with address 169.254.4.147
Also I have found that there is a file in **/run/** called **/run/dhclient.enxXXXXXXXXXXXX.pid** which includes **5931** which is the same number stated in above log. But, What I understood is that, the problem is due to error was that it changed my address to 169.254.4.147**, which means it kicks me that IP and I do not see network anymore.
[ END OF EDIT]
[SECOND EDIT]
Ok, again failure occured this time I am ready to analyse it(I think :D). So, what I found this time are :
1. I checked whether I can pinging to another IP other than 8.8.8.8 and but no success, 8.8.8.8 is still successful.
2. I can not ping 169.254.4.147 (which seem an private IP I dropped to) too! Strange.
3. I checked that **/sys/clas/net/enxXXXXXXXXXXXX/carrier** file to have a network or not, it said 1, so it gives me I am **online**.
4. However, until unplug, I can not see none of the interface or network errors in /var/log/syslog(i.e. system logs). When I unplug and replugger USB cable, all of them revealed.
5. I checked that /etc/resolv.conf is the same as before, i.e not changed after failure.
6. I can still ping to 8.8.8.8 only, not to other addresses.
7. I am trying ; restarting networking service,ifup-down interfaces, IP release/renwe by dhclient -r and dhclient -4 etc. but during all those processes I can still ping to 8.8.8.8.
Is there something stucked socket etc. to 8.8.8.8?
[ END OF SECOND EDIT]
1. Is there other ways/commands to check what is the root cause of the problem?
2. How can I solve it without unplugging/replugging the cable?
[EDIT] I found the answer in answer . Thanks to
mcdizzle's answer. Problem was tcp packages's timestamps, when I closed and add a openDNS as nameserver, those solved my problems.
user458762
Feb 21, 2022, 10:44 AM
• Last activity: Mar 28, 2022, 04:31 PM
1
votes
1
answers
905
views
Why doesn't anacron run the tasks scheduled?
I've set `anacron` to run several tasks, but it seems to fail due to some sort of weird permissions error. This is my `anacrontab`: ```sh # /etc/anacrontab: configuration file for anacron # See anacron(8) and anacrontab(5) for details. SHELL=/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # t...
I've set
anacron
to run several tasks, but it seems to fail due to some sort of weird permissions error.
This is my anacrontab
:
# /etc/anacrontab: configuration file for anacron
# See anacron(8) and anacrontab(5) for details.
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# the maximal random delay added to the base delay of the jobs
RANDOM_DELAY=45
# the jobs will be started during the following hours only
START_HOURS_RANGE=3-22
#period in days delay in minutes job-identifier command
1 5 cron.daily nice run-parts /etc/cron.daily
7 25 cron.weekly nice run-parts /etc/cron.weekly
@monthly 45 cron.monthly nice run-parts /etc/cron.monthly
@daily 1 bashrc.daily rsync -aAX $HOME/.bashrc /run/media/MYUSER/samsung/home/MYUSER/.bashrc
@daily 1 bash_aliases.daily rsync -aAX $HOME/.bash_aliases /run/media/MYUSER/samsung/home/MYUSER/.bash_aliases
@daily 5 variety.daily rsync -aAX $HOME/.config/variety/ /run/media/MYUSER/samsung/home/MYUSER/.config/variety/
@daily 3 testfile.daily rsync -aAX $HOME/Documents/flag.hs /run/media/MYUSER/samsung/flag.hs
@weekly 5 st_apps.daily rsync -aAX $HOME/.local/share/Steam/steamapps/ /run/media/MYUSER/samsung/home/MYUSER/.local/share/Steam/steamapps/
@weekly 15 st_ud.daily rsync -aAX $HOME/.local/share/Steam/userdata/ /run/media/MYUSER/samsung/home/MYUSER/.local/share/Steam/userdata/
@weekly 1 anacrontab.weekly rsync -aAX /etc/anacrontab /run/media/MYUSER/samsung/home/anacrontab
This is the output of journalctl -b --no-pager --catalog | grep anacron
jan. 14 00:02:09 MYPC anacron: Anacron started on 2022-01-14
jan. 14 00:02:09 MYPC anacron: Can't open timestamp file for job cron.daily: Permission denied
jan. 14 00:02:09 MYPC anacron: Aborted
jan. 14 00:02:42 MYPC sudo: MYUSER : TTY=pts/0 ; PWD=/home/MYUSER ; USER=root ; COMMAND=/usr/bin/dd bs=4k of=/etc/anacrontab
jan. 14 00:02:50 MYPC sudo: MYUSER : TTY=pts/0 ; PWD=/home/MYUSER ; USER=root ; COMMAND=/usr/bin/dd bs=4k of=/etc/anacrontab
Could someone *please* prod me in the right direction?
System: Fedora 35
telometto
(2191 rep)
Jan 13, 2022, 11:13 PM
• Last activity: Jan 15, 2022, 11:07 AM
0
votes
1
answers
115
views
Why is a find process getting started by checksecurity in Debian and how to disable it if it's not useful?
With `sudo lsof | grep mounted-drive-name` I found that a `find` process is running on one of my hard drives which I'd like to spare. With KDE's system monitor it shows me that it was started by anacron->checksecurity (the full process tree is: systemd->anacron->sh->run-parts->checksecurity->checkse...
With
sudo lsof | grep mounted-drive-name
I found that a find
process is running on one of my hard drives which I'd like to spare.
With KDE's system monitor it shows me that it was started by anacron->checksecurity (the full process tree is: systemd->anacron->sh->run-parts->checksecurity->checksecurity->check-setuid->find and it is run by user root).
With that command I noticed that most of the time it scans through node_modules folders but also scans folders like ~/.config/chromium/Default/[...]. Afaik I didn't change anything in those folders at least since the last time that this has been running.
I'd like to know why that find process is getting periodically run, if it is useful (for me; and e.g. where one can find its results) and how to disable it (or configure it so that it scans only in a way that's useful).
I ran cat /proc/PID/status
and ps -Flww -p PID
which didn't yield a lot of info about it and couldn't find out if and how such(?) checksecurity scans are useful or whether they running properly.
mYnDstrEAm
(4708 rep)
Jul 22, 2021, 11:39 AM
• Last activity: Sep 2, 2021, 09:49 AM
1
votes
0
answers
15
views
What happens to at-scheduled job when PC is off?
Say I have job scheduled via `at` - what happens when the PC is off during that scheduled time? Will the job be caught up for during reboot? Does this have to be specified? Or comparing this to `cron`: Is there an `anacron`-analogue for `at`? `info at` does not seem to mention the issue.
Say I have job scheduled via
at
- what happens when the PC is off during that scheduled time?
Will the job be caught up for during reboot? Does this have to be specified?
Or comparing this to cron
: Is there an anacron
-analogue for at
?
info at
does not seem to mention the issue.
FelixJN
(14014 rep)
Jun 26, 2021, 05:29 PM
0
votes
0
answers
99
views
anacron is given priority over cron
An extract from the book [Linux-In-Action][1] As you can see from the crontab file, anacron is given priority over cron. the crontab file he is referring is - `/etc/crontab` Consider the below scenario My system boots at `15:00 pm` below was the entry in `/etc/anacrontab` file 1 10 myBackupJob_anacr...
An extract from the book Linux-In-Action
As you can see from the crontab file, anacron is given priority over cron.
the crontab file he is referring is -
/etc/crontab
Consider the below scenario
My system boots at 15:00 pm
below was the entry in /etc/anacrontab
file
1 10 myBackupJob_anacron /home/farhanshirgill/Desktop/scripts/shellscript.sh
This command runs the shellscript.sh
script no more than once a day, 10 minutes
after system boot. The job identifier is myBackupJob_anacron
, and a log file of that name with job status information will be saved to the /var/spool/anacron/
directory.
the shellscript.sh
is kept simple and is responsible to create a file
#!/bin/sh
touch /home/farhanshirgill/Desktop/scripts/fileA.txt
After 10
mins at 15:10 pm
, i can see the file fileA.txt
created in /home/farhanshirgill/Desktop/scripts/
. Everything is okay up to this point of time.
In the *user* specific crontab
file which is edited with crontab -e
, the below entry was made
20 15 * * 0 touch /home/farhanshirgill/Desktop/scripts/fileB.txt
As seen, this should create the file fileB.txt
at 15:20 pm
.
An entry was also made in /etc/crontab
file like below
25 15 * * 0 farhanshirgill touch /home/farhanshirgill/Desktop/scripts/fileC.txt
As seen, this should create the file fileC.txt
at 15:25 pm
.
The files(fileB
& fileC
) which were intended to be created with crontab(system & user ones) don't get created.
Does the entry in /etc/anacrontab
have to do with this behavior. Please advise.
Farhan stands with Palestine
(103 rep)
May 31, 2021, 12:31 PM
0
votes
1
answers
290
views
Cannot run anacron while it seems to be installed (Debian 10)
I'd like to setup a job using anacron on my desktop PC running Debian GNU/Linux 10 (buster). The `anacron` package seems to be installed properly: running `sudo apt install anacron` returns ``` anacron is already the newest version (2.3-28). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgra...
I'd like to setup a job using anacron on my desktop PC running Debian GNU/Linux 10 (buster).
The
anacron
package seems to be installed properly: running sudo apt install anacron
returns
anacron is already the newest version (2.3-28).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
man anacron
opens the man page properly, but surprisingly, anacron -h
returns
-bash: anacron: command not found
What could be possibly going on ?
Thanks !
Raphaël Ventura
(55 rep)
Sep 4, 2020, 11:11 AM
• Last activity: Sep 4, 2020, 11:37 AM
0
votes
1
answers
217
views
Can I set an enviroment variable for a single anacron command?
Consider the following anacrontab file: ~~~ 1 0 bob-job /home/bob/script.sh ~~~ I know I can set variables like this: ~~~ FOO=bar 1 0 bob-job /home/bob/script.sh ~~~ However, can I set a variable just for the `bob-job` line? I know I can do: ~~~ FOO=bar 1 0 bob-job /home/bob/script.sh FOO= ~~~ ... b...
Consider the following anacrontab file:
~~~
1 0 bob-job /home/bob/script.sh
~~~
I know I can set variables like this:
~~~
FOO=bar
1 0 bob-job /home/bob/script.sh
~~~
However, can I set a variable just for the
bob-job
line?
I know I can do:
~~~
FOO=bar
1 0 bob-job /home/bob/script.sh
FOO=
~~~
... but this is not equivalent because it clobbers the existing value of FOO, if any (from the parent environment of anacron), and setting FOO=
to empty is not also equivalent to unset.
BeeOnRope
(559 rep)
Apr 8, 2020, 12:23 AM
• Last activity: Apr 8, 2020, 06:02 AM
0
votes
1
answers
962
views
how to schedule a task that runs a command or script when a user logs on?
I want to program a script that is launched whenever a specific user, let's call it `user` log in. For example, when you log on to the computer with that user or using the `su` command on a terminal. I can use any software such as crontab, anacron or at; or any other similar software. preferably cro...
I want to program a script that is launched whenever a specific user, let's call it
user
log in.
For example, when you log on to the computer with that user or using the su
command on a terminal.
I can use any software such as crontab, anacron or at; or any other similar software.
preferably crontab, if you could:
? ? ? ? ? user /path/script.sh
Francisco de Javier
(1311 rep)
Mar 12, 2020, 11:58 AM
• Last activity: Mar 18, 2020, 08:37 AM
0
votes
1
answers
293
views
How does anacron run at the same time each period?
I am trying to set up a regular backup regime for my desktop running debian stable. Its not always on, so I might miss the required times if I just use cron. But for now thats what I am doing because of the following logic. Doing some tests my weekly backup takes about 3 hours to run. Reading the an...
I am trying to set up a regular backup regime for my desktop running debian stable. Its not always on, so I might miss the required times if I just use cron. But for now thats what I am doing because of the following logic.
Doing some tests my weekly backup takes about 3 hours to run. Reading the anacron man page implies that the timestamps are updated when the job terminates. So on the first week it runs at about 8 am, then if it waits a week since the last timestamp, on the second week it will not run until after 11am (I think anacron is run at startup and then through an hourly timer controlled by systemd). This run's timestamp will get set about 2pm. If we carry on like this, the timestamp will slip into the next day. More importantly it will slip to a time when I am about to go to bed and power off my machine (and the NAS server which it is backing up to will also close down)
There appears to be an attempt to mitigate this in Debian, by having a file called
0anacron
in the /etc/cron.weekly
directory which sets timestamps as the first thing but I can't figure out how it works, because the timestamps would still be updated at the end of the job.
Is there a mechanism I don't understand to stop anacron slowly (or rapidly) slipping the time the run starts backwards.
akc42
(361 rep)
Feb 24, 2020, 02:02 PM
• Last activity: Feb 24, 2020, 02:33 PM
0
votes
0
answers
43
views
Different versions of files in different hours
On my laptop, I have three files: `file`, `file-morning` and `file-afternoon`. I want `file` to be a copy of `file-morning` before 12AM and a copy of `file-afternoon` after 12AM. Ideally, I would like to be able to add another time intervals easily. This all should work no matter whether the laptop...
On my laptop, I have three files:
file
, file-morning
and file-afternoon
. I want file
to be a copy of file-morning
before 12AM and a copy of file-afternoon
after 12AM. Ideally, I would like to be able to add another time intervals easily. This all should work no matter whether the laptop slept, was turned off or hibernated. In given times, I just want to find the correct version of the file.
I do not think that either cron
or anacron
can schedule such job, can they? I mean, I do not see a solution which would not require me to write a script checking the time itself.
My use case are rules for url blocking for a transparent proxy server to prevent myself from browsing certain websites compulsively and learn that there are times for that :-D
Pavel
(101 rep)
Feb 21, 2020, 12:52 AM
• Last activity: Feb 21, 2020, 06:33 AM
Showing page 1 of 20 total questions