kill script  if fsck or e2fsck is waiting on input

Posted on 2008-11-17
Last Modified: 2013-12-26
Operating System: Oracle Enterprise Release 5 Update 1 (RH code base - would be the same as Red Hat release)
Hardware: Sun Microsystems x4100 M2

I am coding a backup server system. Before mounting SAN filesystems, I need to fsck or e2fsck the file systems prior to mounting. If the check fails, it is easy enough to display a message, clean up and remove related processes. The problem that I am thinking about, have not yet encountered via bash script is, if fsck or e2fsck is waiting on user input particularly for whether or not you wish to use alternate superblock. My guess is that it would sit there forever, waiting for an answer. I want to answer no and die. I can't see anything that would say to call that an error and die. I would like to know if there is a way to wait 2 seconds or so waiting on input to just do same tasks as if the check had failed? if trap, what would i trap for. If there some other way to answer no, display a message and die? Is there some undocumented flag or alternate fsck utility that would just error if it got to that point?

Thank you,
Mark N.

Question by:ManoaHI
    LVL 43

    Accepted Solution

    never tried, but You could test

    yes no | e2fsck -p /dev/sdXY
    if [ $? -le 1 ]; then
     echo e2fsck finished ok
     echo e2fsck left fs unclean

    Author Comment

    Thanks, I'll put the -p option and take out the -y in so that it works with Solaris as well as Linux. By any chance does anyone know how to force a disk to ask to use the alternate superblock (essentially corrupt it on purpose) to see if that works?

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now