0

I'm looking to automated fsck on my FreeBSD server. I have an idea how to do this, but because it's running pretty powerful commands, I'd like some more eyes on it before I set it to run.

Step 1. Cron job. My cron will look something like this: 0 17 * * 0 myfsckscript.sh > /usr/local/var/log/fscklog/$(date).log, to run at 5PM every sunday. It will be run from root's crontab, because what I'm doing requires root permissions.

The script goes something like this:

init 1 # Run single-user mode, so fsck can run correctly
fsck -y # Run fsck
fsck -y # Run again, to clean up. Makes my machine act better
init 5 # bring it back up.

My main concerns follow:

  • Does running this pose any substantial dangers I should know about?
  • Are there any errors in my script?
  • Anything I should add?
  • Did I actually get it right?

I'm sorry this is mostly a confirmation question, but with my level of skill with sh I'm not comfortable setting this to run without someone more experienced taking a look first.

Eric Miller
  • 429
  • 4
  • 11

1 Answers1

1

What about just add this to /etc/rc.conf:

fsck_y_enable="YES"
background_fsck="NO"

Basically, means to run fsck -y and don't try to run in background, so depending on the size of your disks, this could take a while to finish.

nbari
  • 25,603
  • 10
  • 76
  • 131
  • This looks like it's perfect for me; I'll schedule a weekly reboot and it should keep things running smoothly. Just so I'm 100% clear, this will run `fsck -y` every time I boot into multi-user mode? – Eric Miller Mar 28 '17 at 21:30
  • why would you like to reboot the server, there is no need to so, `fsck_y_enable` will execute `fsck -y` on boot time but only if needed – nbari Mar 28 '17 at 22:34