Code:#!/bin/sh mkdir ibbi RETVAL="$?" if [ "$RETVAL" -eq 0 ]; then echo "it went well" else echo "it failed" fi
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
Code:#!/bin/sh mkdir ibbi RETVAL="$?" if [ "$RETVAL" -eq 0 ]; then echo "it went well" else echo "it failed" fi
Is there a label/goto in scripting to tell it to repeat the command?
[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.
[quote author=redhead link=board=9;threadid=3613;start=0#36762 date=1023302571]
[/quote]Code:#!/bin/sh mkdir ibbi RETVAL="$?" if [ "$RETVAL" -eq 0 ]; then echo "it went well" else echo "it failed" fi
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:
&& 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 itCode:mkdir foobar && echo "it worked" || echo "it failed"![]()
[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:
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 workCode: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![]()
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 xaaCode:#!/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"
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 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...
Bookmarks