Return to Older Projects

FreeNAS FSCK cron job


Are you running FreeNAS? Here’s a quick little PHP script to run a fsck on all your defined mount points to make sure the file system is clean. Sends you an e-mail when/if it finds some problem. It does not automatically fix the problem since you may need to dismount and we probably don’t want to do that automatically! Uses the FreeNAS Email Reports configuration for it’s SMTP info. You can still leave Email Reports disabled, just check the Enable box, fill in the SMTP data, then clear the check box. The Email reports configuration is still saved and usable even if the utility is itself is left disabled.


I’m running off the LiveCD version of FreeNAS. Here’s how I’ve got FSKtest configured on my system. You might want to do it differently! By the way, this also might give you some ideas on how to customize your FreeNAS system even though you’re running the LiveCD variant.

On one of my mounted disks, I’ve got a top level /custom/ directory created. It’s actually at the top of one my of SMB mounted shares so that I can access it easily from my windows box in case I need to edit the script files.

Unpack the zip file into the /custom/ directory. That gets the customized scripts into a place where I can edit them from my windows system.

Now, to get the custom files to a place where FreeNAS can execute them, I set up a boot time copy command to copy the files from the SMB shared disk to the LiveCD RAM drive. This way your customization files survive a reboot, even though you’re only running of a boot CD and RAM disk. Yeah, you probably could execute directly from the shared disk, but I might want to write a script some time that dismounts that shared disk! Stick a PostInit command script in FreeNAS like
ie copy all the .php files from the /custom/ directory over to the local /etc/inc/ directory.

That gets the script to a good executable place. Now don’t forget to fill in your mail server info in the FreeNAS Email Report screen. Yes, you might have to check the enable box, fill out your info and then uncheck the enable. That’s OK and should work fine.

FSCKtest.php just needs to be scheduled to run periodically. Create a cron job something like
one that executes the fscktest.php script once a day at noon. Don’t forget, reboot once so that PostInit command fires and moves the files to the /etc/inc directory, otherwise
your cron job will fail!

This ZIP file contains the fscktest.php script as well as a TestEmail.php script to make sure you’ve got your e-mail configured correctly. Download it now from here.


Skip to comment form

    • Pierre on August 6, 2010 at 3:39 am

    Hi there,

    “phpmailer/class.phpmailer.php” is missing from the zip file. Do you use the one from SourceForge ?.


    • admin on August 6, 2010 at 5:16 am

    Interesting, was in the Freenas build before. I haven’t updated for awhile so perhaps the recent builds of Freenas don’t include phpmailer anymore?

    • Alex on September 25, 2010 at 9:43 pm

    Yeah they don’t appear to.

    This code below seems to work for 0.7.2:
    $error = “”;
    email_send(“”, “Subject”, “Message”, $error);

    I’ve modified the PHP script to just echo “Hello”; for now because I’m having some issues when using cron and executing php like you’ve shown in this tutorial, when doing an “Run Now” on FreeNAS GUI it freezes.

    I can confirm that running normal .sh scripts work fine. I’ve run the simple echo PHP script in SSH and that works to.

    Any suggestions would be appreciated, cheers.

    • admin on September 26, 2010 at 8:35 pm

    Not sure how much I’m going to be able to help. I’m running, old, old Freenas version (0.686). I guess I aught to update one of these days…..

    Maybe someone over in the Freenas forum can assist –

    Searching the web a bit, looks like PHPMailer was replaced with msmtp SMTP mail client in v0.69 RC 1

Comments have been disabled.