Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
install command in linux 1 61
Set-Top-Box hardware and Open Source! 8 387
WiFi Router device supports GPON! 3 154
awk to variable in bash 2 156
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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