Solved

Waiting for command to complete in startup script, how to avoid waiting indefinetely?

Posted on 2006-06-09
3
311 Views
Last Modified: 2010-04-21
Dear experts
As it's usually the case when we make changes things stop working as they used to... We've had to change the CF cards on our linux electronics, and these new cards no longer get mounted in the startup script (/etc/rc2.d/S99viper) as before. It seems the driver that handles this new CF card takes longer to activate and is not ready by the time it get's checked and then mounted.  However I can mount the CF manually without any trouble once the system has finished booting.

This is what the startup script does to the CF:
#Check compact flash
fsck -y /dev/hda1
# Mount CF
mount /mnt/CF

I would like the script to test if the command fsck has been succesful and if not wait till it is. Is this script correct?

while ! fsck -y /dev/hda1
           sleep 2
end

However it seems a bit dangerous, couldn't it get blocked for ever?, is there a simple way to put a timeout of some sort or to avoid the startup script to be stuck in this test indefinetely?

Thanks for your help!
0
Comment
Question by:ealdaz
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
root_start earned 400 total points
ID: 16874720
Hi ealdaz,

You can try the following script:
==============================================================================================
#!/bin/sh

maxCheckCount=10

checkCount=1

fsck -y /dev/hda1
returnValue=${?}
while [ ${returnValue} -ne 0 ]
do
         fsck -y /dev/hda1
         returnValue=${?}

         if [ ${checkCount} -ne ${maxCheckCount} -o ${returnValue} -ne 0 ]
         then
                checkCount=`expr ${checkCount} + 1`
         else
                break
         fi
done
==============================================================================================

I hope it helps you. =0)
0
 
LVL 3

Expert Comment

by:root_start
ID: 16874738
Ops... I forgot to add the sleep.

Add it after the following line in the script above:
            checkCount=`expr ${checkCount} + 1`
            sleep 5

Also, if you want to be more specific about the error fsck is returning, in the man you will find the possible return values for it: "man fsck".

You will find something like this:
0 - No Errors
1 - File system errors corrected
2 - System should be rebooted
4 - File system errors left uncorrected
8 - Operational error
16 - Usage or syntax error
32 - Fsck canceled by user request
128 - Shared library error

I did not mention that I got the values above from a linux box.

Again, I hope it helps. =0)
0
 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 100 total points
ID: 16879305
I wonder whether there's much point waiting in a loop - perhaps the kernel module to drive the new card is not loaded yet? You could earlier on in the boot scripts modprobe that module and do a sleep (if the flash takes a while to initialise)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

23 Experts available now in Live!

Get 1:1 Help Now