Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i create a game board using shell script 2 78
Debian 3.16.7 3 152
Unix / Linux grid computing 5 163
incorrect file reading in bash 7 137
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

820 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