Results 1 to 6 of 6

Thread: linux script/program continue statement help!

Hybrid View

  1. #1

    linux script/program continue statement help!

    Ok, here is the problem. Im writing a script/progran in/for linux and unix at work that will speed up the install processes for all of our Linux/Unix installs. I have a small segment of code that i cannot get to work and i cannot figure out why. First ill explain what it is supposed to do. Basically the user will already have put a specific cd into the cd-rom and the script will try to mount it. If linux cannot mount the cd, then it will prompt the user to insert the cd and eject the cdrom (and then hit enter). After the user hits enter the "continue" is supposed to bring the script back to the beginning of the loop... but it doesnt. Instead it continues executing all of the commands throughout the rest of the loop. This may be an easy problem but i fail to see why it doesnt work. If someone could help that would help me greatly because im really hung up on this point. I know several ways to get around this so you need not post a way to work around it, im interested in finding out why this didnt work exactly. If im lacking information or anything to that affect tell me and ill gladly post more. Thanks a ton if you can help!



    loop2=y
    while [ $loop2 = y ]
    do

    umount /mnt/cdrom 2> /dev/null
    echo
    echo Mounting cdrom...
    echo "*note: If a window pops up when the cd is mounted you may close it."
    echo

    ## THIS IS THE PART THAT DOESNT WORK
    mount /mnt/cdrom 2> /dev/null && loop2=n || ( echo The cd did not mount properly. Please ensure that the ServeRAID Manager && echo -n "cd is inserted and hit enter: " && eject /mnt/cdrom && ( read blank ; continue ) ) 2> /dev/null
    ##
    echo

    echo Installing ServeRAID Manager....
    rpm --install /mnt/cdrom/linux/manager/RaidMan-4.84.i386.rpm 2> /dev/null

    echo Copying ipssend to /usr/bin and changing permissions to 777....
    cp /mnt/cdrom/linux/cmdline/ipssend /usr/bin 2> /dev/null
    chmod 777 /usr/bin/ipssend
    echo
    umount /mnt/cdrom 2> /dev/null
    echo Installation of ServeRAID is now complete. You may remove the cd.
    done


    --Morphman
    PS: This is the bash


  2. #2

    Re: linux script/program continue statement help!

    what the heck are you trying to do?

    Code:
    while true
    do
    
    while true
    do
    
    umount /mnt/cdrom >/dev/null 2>&1
    echo "Mounting cdrom... if something pops up, close it"
    
    if [ mount /mnt/cdrom >/dev/null 2>&1 ]
    then
    
    break
    
    else
    
    echo "The cd did not mount properly. Please reinsert cd"
    
    eject /mnt/cdrom
    
    read blank
    continue
    
    fi
    done
    
    echo Installing ServeRAID Manager....
    rpm --install /mnt/cdrom/linux/manager/RaidMan-4.84.i386.rpm 2> /dev/null
    
    echo Copying ipssend to /usr/bin and changing permissions to 755....
    cp /mnt/cdrom/linux/cmdline/ipssend /usr/bin 2> /dev/null
    chmod 755 /usr/bin/ipssend
    echo
    umount /mnt/cdrom 2> /dev/null
    echo Installation of ServeRAID is now complete. You may remove the cd.
    
    done
    Are you sure it's such a great idea to make the binary 777?

    I'm not sure if this does exactly what you want, but it should.

  3. #3

    Re: linux script/program continue statement help!

    I was trying to do basically what you posted and your method is a lot cleaner so ill try that. I just started actually writing large scripts a couple of weeks ago so i still do a lot of things in a rather messy manner. One thing that bugs me though, why wont this work:
    code:
    mount /mnt/cdrom || ( echo "blahblahblah" && echo "blah blah blah" && var=something && read blank && continue )

    If the mount command fails it should echo "blahblahblah" then echo "blah blah blah" then set var=something then wait for the user to hit enter and then restart the loop right? Well, when i tried this first method it never ran the continue statement to restart the loop. It would always finish the rest of the loop. So then i just started experimenting and tried changing the syntax a little bit to this:

    code:
    mount /mnt/cdrom || ( echo "blahblahblah" && echo "blah blah blah" && var=something && ( read blank ; continue ) )

    just to try somethign different. It should do the same thing right? Putting it in a parenthesis with a semi colon dividing the two just says do one then the other right? Well, things are getting messy on this script. i might start over anyway, hehe.

    As for doing a chmod 777 it doesnt really matter for what im doing. Security is not an issue. I do many installs and often times swipe the hard drive the same day or within a few hours. I work for IBM testing hard drives with different configurations so one server is never up for very long.
    Well, thanks for the help so far! Im going to get back to experimenting!

    --Morphman


  4. #4

    Re: linux script/program continue statement help!

    Well first of all, I've never heard of this "()" construct. I think you're thinking of "{}", with the curly braces.

    Secondly, && is not the operator that you want to use in this situation. && will only execute the next statement if the previous one was successful, which is not really what you care to do here. (if echo fails, nothing happens after that).

  5. #5

    Re: linux script/program continue statement help!

    Most of the constructs that i have used have been based off of a unix book that was written in the 80s. So far nearly everything ive learned from there has held true for bash scripting.
    I would agree that using the && is a bit silly in these cases. I worked through a few of my scripts and changed it around. I guess i was just excited to use it at the time because it allowed me to condense a whole bunch of commands into one command line--which is messy and really serves no purpose. Thanks for the help, i think ive figured out all of my problems.

    --Morphman

  6. #6

    Re: linux script/program continue statement help!

    I would agree that using the && is a bit silly in these cases. I worked through a few of my scripts and changed it around. I guess i was just excited to use it at the time because it allowed me to condense a whole bunch of commands into one command line--which is messy and really serves no purpose.
    Well, usually you'll only want to do that is if your if statement has only one command in it, like so:

    Code:
    if [ some condition ]
    then
     do something
    fi
    That could be replaced with this:

    Code:
    [ some condition ] && do something
    But I really wouldn't want to chain too many together.

    Thanks for the help, i think ive figured out all of my problems.
    Uh, k. :P

Similar Threads

  1. Assembly program error on linux
    By omidkamangar in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 05-29-2006, 12:46 PM
  2. Hardware check program in Linux
    By Compunuts in forum Linux - General Topics
    Replies: 3
    Last Post: 12-10-2004, 10:17 PM
  3. Linux Program Installations
    By Spartan117mjlnir in forum Linux - General Topics
    Replies: 6
    Last Post: 09-16-2004, 01:26 AM
  4. Write me a new script or program?
    By Compunuts in forum Programming
    Replies: 8
    Last Post: 08-28-2004, 10:38 PM
  5. Best File Sharing Program In linux
    By gmoreno in forum Linux - Software, Applications & Programming
    Replies: 27
    Last Post: 01-03-2002, 12:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •