Solved

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

Posted on 2006-06-09
3
310 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

16 Experts available now in Live!

Get 1:1 Help Now