Check if actions in bash shell script are performed well
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
The right solution is most times to check the exit status of the given application. After all, that's what the exit status is for.
mysqldump will spit an integer when it's done running. Usually, 0 means success, and any other things means that something bad happened. The concrete value can be used for different errors. Usually, the man of info page should specify that.
In any case, this return code can be used in many ways to branch your script depending on the success of failure of a given instruction.
In addition, in bash, 0 is true, while anything else is false. So, you could perfectly do something like:
while ! <command>
That will loop indefinitely until the exit status of <command> is zero (success).
You can even use the logical AND and OR operators to bifurcate
What part of 'i92guboj' post indicates exit code or status? Most properly written applications provide a 'exit code'. You will use that 'exit code' or status to decide within your script a specific operation to be performed relative to the indicated error.
proNick, the problem with saving the output to a variable, if you ask me, is that variables have a very finite space available. So, if anything nasty happens the output will probably not fit into your variable. If you really want to save the stuff for reference, redirect both stderr and stdout to a file, and for the rest, use the exit status to determine if the thing was successful. If it was, there's absolutely no point in parsing any output, is there? If the exit status is not zero, then you can go to the file and grep, sed, cut or awk it to your desire.
But if you are going to do intensive parsing in long logs, bash is probably not the best.