LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 08-29-2008, 02:48 AM   #1
Swapna173
LQ Newbie
 
Registered: Dec 2007
Posts: 25

Rep: Reputation: 15
Return Value


Hi Guys,

I wanted to track the return value of certain errors in the linux process. How can i get the error numbers.

I wrote a script which takes database dumps and process with sqlldr and procedure.

In this case dumps exported successfully, but loader failed due to insufficient space. So i need to check the return value of insufficient space for each process and proceed. The script should stop process to proceed further in case of only insufficient failure.
 
Old 08-29-2008, 03:23 AM   #2
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
hello,
$? will normally give you the exit code in bash
in a script you would..
./run script (or command)
echo $? OR EXITSTATUS=$?;echo ${EXITSTATUS}

As long as the script or command does create the correct exit codes...sometimes you might find a command or script doesn't support them. Generally an error/failure would produce an exit code of 1 and success is generally exit code of 0.

If you have error checking in your scripts and you execute other scripts of your own and want to provide error exit codes for your own scripts, then you can when exiting a script do it with...
exit 0 #script completed successfullly
OR
exit 1 #script failure

Generally i use them in my own scripts when required, i run checks on whatever the script is supposed to have done successfully and then depending on those checks i then exit the script with status codes of 1 or 0

hope this helps, regards

ps- without seeing the script and the commands its hard to say more than this
 
Old 08-29-2008, 03:24 AM   #3
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
So, you want to stop a script when the disk is full, is that what you want?
What about putting something like that in your script:
Quote:
fill=$(df -h /your/mount/point | tail -1 | sed "s/ */:/g" | cut -d: -f5)
[ ${fill%%%} -gt 99 ] && exit 1

Last edited by Agrouf; 08-29-2008 at 03:26 AM.
 
Old 08-29-2008, 04:30 AM   #4
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
I'm intrigued now...more often lately (twice in the last two days) have i suddenly come across this %%% with variables. Can you point me in a direction of a sufficient doc for this...

I looked and found it does some kind of substitution type of thing...removing values from the variable and stuff ...as you can tell i don't really have a clue what it does

Last edited by helptonewbie; 08-29-2008 at 08:03 AM.
 
Old 08-29-2008, 06:12 AM   #5
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
Actually, %% trims on the right.
let's consider this variable:
Quote:
var="the file system is full at 90%"
I want to get the last % off:
Quote:
echo ${var%%%}
the file system is full at 90
Now let's say I want to remove the last word. How do I do that?
Easy: I do exactly the same thing, but instead of removing %, I remove a space and anything that's after it (in regular expression, it means " *":
Quote:
echo ${var%% *}
the
Oops! Actually, " *" matches just after the first word. That is because %% takes the biggest match possible.
Fortunatelly, I have another trick: the % is the same as %%, but matches the smallest possible match:
Quote:
echo ${var% *}
the file system is full at
Good! I'm removed the last word.
But what if I want to remove the first word?
Well, there is another trick: the '#' is exactly like '%' (and '##' is like %%) but on the left:
Quote:
echo ${var##* }
90%
echo ${var#* }
file system is full at 90%
The documentation for this is in the bash documentation (man bash), which is very, VERY looooong.

Last edited by Agrouf; 08-29-2008 at 06:18 AM.
 
Old 08-29-2008, 08:10 AM   #6
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Ah cheers, after having a little go myself i get it now thanks...

%%[expression to match to remove everything from first match to end of contents of variable]*

##[go the opposite way]*
%%[t] means remove the last character if it matches t

well you may not understand what i wrote hear but the main thing is i get it

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you return a value with grep ? pppaaarrrkkk Linux - Newbie 2 11-30-2007 07:37 PM
LXer: The Return of Them LXer Syndicated Linux News 0 05-21-2006 09:03 PM
return value neerajchaudhari Linux - Newbie 1 08-29-2005 02:42 AM
return 0 or return(0) in C? servnov Programming 5 01-08-2005 05:39 PM
return linuxanswer Programming 4 10-26-2003 12:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration