Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Checking the finishing status of a command in a script
Results 1 to 10 of 10

Thread: Checking the finishing status of a command in a script

  1. #1

    Checking the finishing status of a command in a script

    Hey. I'm trying to improve my backup script. I found out one problem with it last night in a bad way. It prompts to put in a cd and hit ctrl + d, and I did but the burner was still checking out the disc and burncd returned an error and it continued through the script and deleted that image. So I'm going to have to start all over. But first, I want to make sure it will never happen again. So can anyone suggest an alternative to the following piece of code that will do it? Thanks.

    Code:
    for i in `ls xa[a-z]`
      do echo -e "insert blank disc and press ctrl+d"
      cat >> /dev/null
      echo "recording cd"
      burncd -f /dev/acd0c -s 2 blank data $i fixate
      echo "removing file"
      rm $i
    done

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Checking the finishing status of a command in a script

    Code:
    #!/bin/sh
    mkdir ibbi
    RETVAL="$?"
    if [ "$RETVAL" -eq 0 ]; then
       echo "it went well"
    else
       echo "it failed"
    fi

  3. #3

    Re:Checking the finishing status of a command in a script

    Is there a label/goto in scripting to tell it to repeat the command?

  4. #4
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Checking the finishing status of a command in a script

    [quote author=Evil Honkey Kenshi link=board=9;threadid=3613;start=0#36879 date=1023369793]
    Is there a label/goto in scripting to tell it to repeat the command?
    [/quote]
    Label/goto?? Dont think there is such a thing, why not make the code segments as functions, then call the one repressenting the goto label in the case..
    Repeat ??.. Isn't while(true) do baz end.. or for foo do bar done.. enough?

    Shouldn't be too hard to figure out a way, to rewrite a if() statement into a while loop..
    Just remember the 'continue' and 'break' keywords.. 'break 2' if you want to break out of two joined loops at the same time.

  5. #5

    Re:Checking the finishing status of a command in a script

    [quote author=redhead link=board=9;threadid=3613;start=0#36762 date=1023302571]
    Code:
    #!/bin/sh
    mkdir ibbi
    RETVAL="$?"
    if [ "$RETVAL" -eq 0 ]; then
       echo "it went well"
    else
       echo "it failed"
    fi
    [/quote]

    I know I hate it when people post stuff that makes my stuff look bad, but this is just sooooo inefficient (to code, and to run). Here's what it should really look like:

    Code:
    mkdir foobar &&
    echo "it worked" ||
    echo "it failed"
    && means 'execute the next line only if this one succeeded', and || means 'execute the next line only if this one failed. Since they're chained together, if mkdir fails, the first echo will be skipped, and the second echo will pick up on the nonzero return value of mkdir, and execute. Try it

  6. #6

    Re:Checking the finishing status of a command in a script

    [quote author=Evil Honkey Kenshi link=board=9;threadid=3613;start=0#36761 date=1023302338]Hey. I'm trying to improve my backup script.[/quote]

    I would have done it like this:

    Code:
    for i in $(ls xa[a-z])
      do echo -e "insert blank disc and press enter"
      read 
      echo "recording cd"
      burncd -f /dev/acd0c -s 2 blank data $i fixate &&
      echo "removing file" &&
      rm $i
    done
    I know there's a way to put the last three lines of the for loop into a simple while loop so that it will keep happening until it works, but I'm on a windork box so I can't test any of this, and I don't want to post anything unless I'm sure it'll work

  7. #7

    Re:Checking the finishing status of a command in a script

    Ok, I seem to have gotten it to work functionally, but it gives an error message while it's running. I can't tell exactly what the problem is though. Here is a piece of the output and my complete code so far. Thanks for all the help so far.

    Code:
    start recording to cd
    insert blank disc and press enter
    /usr/local/sbin/backup: [: : integer expression expected
    
    recording cd from xaa
    Code:
    #!/usr/local/bin/bash
    cd /usr
    echo "backing up system"
    gtar -cvM -L 649000 -f xaa -f xab -f xac -f xad -f xae -f xaf -f xag -f xah -f x
    ai -f xaj -f xak -f xal -f xam -f xan -f xao -f xap -f xaq -f xar -f xas -f xat
    -f xau -f xav -f xaw -f xax -f xay -f xaz / --exclude '/mnt' --exclude '/tmp'
    echo "start recording to cd"
    for i in `ls xa[a-z]`
      do echo "insert blank disc and press enter"
      until [ "$RETVAL" -eq 0 ]
      do
        read
        echo "recording cd from $i"
        burncd -f /dev/acd0c -s 2 blank data $i fixate
        RETVAL="$?"
        if [ "$RETVAL" -ne 0 ]; then
          echo "failed recording; hit enter to try again or ctrl+c to abort"
        fi
      done
      echo "removing file"
      rm $i
    done
    echo "done"

  8. #8
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Checking the finishing status of a command in a script

    Its your first until [ "$RETVAL" -eq 0 ] do, at this point $RETVAL is NILL, so you endup with a until [ -eq 0 ] do this bash do not understand.

  9. #9

    Re:Checking the finishing status of a command in a script

    [quote author=redhead link=board=9;threadid=3613;start=0#37144 date=1023479670]
    Its your first until [ "$RETVAL" -eq 0 ] do, at this point $RETVAL is NILL, so you endup with a until [ -eq 0 ] do this bash do not understand.
    [/quote]

    And the solution to this, of course, is to put "RETVAL=1" somewhere near the beginning of the script...

  10. #10

    Re:Checking the finishing status of a command in a script

    That was my guess. I've already done that, just haven't tried it out yet. Thanks.

Similar Threads

  1. command in bash script to check if tar is currupt or not
    By expresstom in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 05-15-2011, 09:07 PM
  2. Newbie - Trouble finishing Openfire setup wizard
    By sabkuchindia in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 04-20-2009, 05:41 PM
  3. Replies: 0
    Last Post: 12-06-2007, 07:51 AM
  4. Checking stats
    By mcdougrs in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 10-24-2003, 06:21 AM
  5. Web script for server status
    By Schotty in forum Linux - Hardware, Networking & Security
    Replies: 5
    Last Post: 05-19-2003, 06:07 AM

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
  •