kill script if fsck or e2fsck is waiting on input

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.

Who is Participating?
ravenplConnect With a Mentor Commented:
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
ManoaHIAuthor Commented:
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?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.