Solved

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

Posted on 2006-06-09
3
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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