Hot answers tagged

4

This original advice applies only to Debian-based distributions: The two crontab segments you've shown are not the same crontab. So your jobs are running twice (once from /etc/cron.d/rsnapshot and once from crontab -l). Remove one set, for example with sudo crontab -r, and it'll start working properly. The next suggestion is to ensure that sync_first is ...


4

You can use Anacron for this, it is designed to run jobs at certain intervals without assuming that the system is on continuously. If a job is supposed to be run every month, Anacron will check whether it has run in the previous month, and run it if it hasn't (and remember that it doesn't need to run it again for another month). In Debian derivatives, ...


3

The crontab entry you've written is equivalent to 0 0-23/12 * * * . /X.sh This requests execution on the hour between midnight and 11pm, using 12-hour steps — so cron will run the job every day at midnight and noon.


3

Your perl script has open CSV2, "<csv2" or die; ... open CSV1, "<csv1" or die; Where are those files located? cron's current directory is the home directory of the user. If the files are in the "newitems" directory, you have to cd there first. Make sure you're not making any other assumptions about the environment in your programs. I find this is ...


2

The email will be sent every time X.sh finishes running, whenever that is. cron itself will send a job's output by email by default, to the relevant crontab owner or whatever MAILTO is set to; you could use that instead of manually calling mail.


2

You could do this in several ways: Single cron entry 0 15 * * 6 job1; job2; job3 Note that using semicolons means that job2 (and job3) run no matter whether the previous jobs were successful (RC=0) or not. Use && between them if you wish to change that. Multiple cron entries 0 15 * * 6 job1 0 15 * * 6 job2 0 15 * * 6 job3 Or as you ask, ...


2

You need to either use tar --no-recursion or find ... ! -type d because each time your find is listing a directory, tar is recursively copying all of it. Also, couldn't you simply avoid the copy and do a -C dir . for each dir in your array, eg: args=() for f in "${folders_to_backup[@]}" do args+=("-C" "$f" ".") done tar -czf "/home/myuser/backup.tgz" "$...


2

It seems fcron is the right tool: "fcron makes no assumptions on whether your system is running all the time or regularly : you can, for instance, tell fcron to execute tasks every x hours y minutes of system up time or to do a job only once in a specified interval of time."


2

Each user has its own crontab. By allowing the non-root users to write a root's crontab you make a security breach in your system, this is why crond rejects a file with such permissions. If you need to allow non-root accounts to perform some actions that require root privileges then consider to use sudo


2

Here is a more robust form that correctly handles spaces (or even newlines) in filenames and directory names. find . -type f -name '*.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].qz' -exec sh -c 'fdate="${1%.qz}"; fdate="${fdate##*.}"; [ "$fdate" "<" "$(date +%F -d "7 days ago")" ] && rm "$1"' find-sh {} \; This involves a lot of shell trickery ...


2

You have a couple of options here: Check the modification date of the file to see if it's being updated: ls -l /var/backups/your-file.sql If you haven't quite migrated over to systemd yet, cron should be logging to /var/log/syslog, in which case you can do something like this and check the timestamps: cat /var/log/syslog | grep -i cron If you are ...


1

After some extended discussion it appears that the filesystem may corrupted. As an example, rm -rf fails - as root - on a normal tree of files. After unmounting the filesystem, fsck identified it as NTFS. Frustratingly I have seen NTFS fail on other Linux-based platforms under the heavy loads incurred from rsnapshot. There's nothing sufficiently repeatable ...


1

I can't post a comment, but here is the command to create empty test files: for i in {0..50};do touch blah.`date "+%Y-%m-%d" -d "$i days ago"`.qz ;done I believe Dave's answer does the trick. (I needed to complete the for command with '; do') A great one liner for cron.


1

mailx only sends mail if you pass it the destination address on the command line. When you run it with no arguments, it reads interactive commands from its standard input. Beware that your tests fed it garbage which has been interpreted as commands; some of these commands may have corrupted your mailboxes, sent out emails, etc. Tell mailx to run mailx -t, ...


1

The cron daemon takes crontabs from several files. Dir /etc/cron.d and file /etc/crontab are special, they can be manually edited and the daemon will always see the new version automatically. Also these are the only crontab files which have also username field. The crontabs of individual users (usually in /var/spool/cron/crontabs) are not re-read ...


1

Is the line you showed extracted from the output of crontab -l or did it come from a file named crontab? The running crontabs are usually found in a directory under /var/spool. This location can vary. The actual crontabs are usually named according the the userid they apply to. It is common to extract the crontab to a file in order to edit it. However,...


1

Usually, cron sends the output of the jobs it runs to the relevant user; so -v is useful there because you get an email with the full output of the rsync command. On a correctly-configured system, even mail to root goes to the appropriate user. For this to work you need mail to be setup appropriately on the system running cron; that used to be common on ...


1

Turns out there was an alias defined for root in /etc/mail/aliases and this is where it was coming from. There's no way for me to bypass it per-command with this on, as any mail sent to root's mailbox will automatically get forwarded to that alias.


1

I thought that maybe as "@steeldriver" user said, the network couldn't have been ready yet when the system booted, hence I edited and added "sleep 120" before the command. Now it is "@reboot sleep 120; /path/to/my/script.sh > /home/myuser/itworks.txt 2>&1". It simply works, it creates the file itworks.txt and if you "cat" it, you'll get all the info.



Only top voted, non community-wiki answers of a minimum length are eligible