Last active
December 18, 2018 02:18
-
-
Save allenyllee/39074c2765d2fc90e91e096be6b88dc0 to your computer and use it in GitHub Desktop.
crontab jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# automatically repair filesystems with inconsistencies during boot | |
#sudo cp rcS /etc/default/ | |
# automatically repair filesystems with inconsistencies during boot | |
# linux - What should I do to force the root filesystem check (and optionally a fix) at boot? - Unix & Linux Stack Exchange | |
# https://unix.stackexchange.com/questions/400851/what-should-i-do-to-force-the-root-filesystem-check-and-optionally-a-fix-at-bo/400927#400927 | |
sudo sed -i 's|GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX="fsck.repair=yes"|' /etc/default/grub | |
sudo update-grub | |
#copy ./reboot_job to /etc/cron.d | |
sudo cp ./reboot_job /etc/cron.d | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# automatically repair filesystems with inconsistencies during boot | |
FSCKFIX=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DO NOT EDIT THIS FILE - edit the master and reinstall. | |
# (/tmp/crontab.IU8GJx/crontab installed on Fri Aug 11 17:41:11 2017) | |
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $) | |
# Edit this file to introduce tasks to be run by cron. | |
# | |
# Each task to run has to be defined through a single line | |
# indicating with different fields when the task will be run | |
# and what command to run for the task | |
# | |
# To define the time you can provide concrete values for | |
# minute (m), hour (h), day of month (dom), month (mon), | |
# and day of week (dow) or use '*' in these fields (for 'any').# | |
# Notice that tasks will be started based on the cron's system | |
# daemon's notion of time and timezones. | |
# | |
# Output of the crontab jobs (including errors) is sent through | |
# email to the user the crontab file belongs to (unless redirected). | |
# | |
# For example, you can run a backup of all your user accounts | |
# at 5 a.m every week with: | |
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ | |
# | |
# For more information see the manual pages of crontab(5) and cron(8) | |
# | |
# m h dom mon dow command | |
SHELL=/bin/bash | |
HOME=/ | |
MAILTO="[email protected]" | |
#This is a comment | |
# use || to prevent filesystem fail to write to log file which cause command skipped: /sbin/shutdown -r &>> /var/log/reboot.log || /sbin/shutdown -r | |
#0 3 * * 3 root echo reboot &>> /var/log/reboot.log; date &>> /var/log/reboot.log; /sbin/tune2fs -c 1 /dev/nvme0n1p2 &>> /var/log/reboot.log || /sbin/tune2fs -c 1 /dev/nvme0n1p2; /sbin/shutdown -r &>> /var/log/reboot.log || /sbin/shutdown -r | |
#5 3 * * 3 root echo reboot &>> /var/log/reboot.log; date &>> /var/log/reboot.log; /sbin/tune2fs -c -1 /dev/nvme0n1p2 &>> /var/log/reboot.log || /sbin/tune2fs -c -1 /dev/nvme0n1p2 | |
#0 3 * * 6 root echo reboot &>> /var/log/reboot.log; date &>> /var/log/reboot.log; /sbin/tune2fs -c 1 /dev/nvme0n1p2 &>> /var/log/reboot.log || /sbin/tune2fs -c 1 /dev/nvme0n1p2; /sbin/shutdown -r &>> /var/log/reboot.log || /sbin/shutdown -r | |
#5 3 * * 6 root echo reboot &>> /var/log/reboot.log; date &>> /var/log/reboot.log; /sbin/tune2fs -c -1 /dev/nvme0n1p2 &>> /var/log/reboot.log || /sbin/tune2fs -c -1 /dev/nvme0n1p2 | |
# check if the filesystem were corrupted and became readonly. if yes, set "Maximum mount count" to 1 to trigger fsck on next reboot, and reboot system. | |
0 3 * * * root echo $(printf "test ";date) &>> /var/log/reboot.log || (/sbin/tune2fs -c 1 /dev/nvme0n1p2 && systemctl reboot -i &>> /var/log/reboot.log) | |
5 3 * * * root echo $(printf "test ";date) &>> /var/log/reboot.log || (/sbin/tune2fs -c -1 /dev/nvme0n1p2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment