LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-08-2012, 07:19 PM   #1
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Rep: Reputation: 31
chkconfig return values


Hello all,

I am wanting to use the 'chkconfig' command in a script and would to check the return value to make sure the command was issued properly. To check its return values on a mishappen run, I ran something like 'chkconfig --add adfasdf | echo $?' and it returns 0. I would expect it to return something other than 0 since adfasdf is nonsensical and does not exist. I checked the man pages but I don't see anything about the return values in there. What am I doing wrong?

Thank you for any help you can provide,
Michael
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-09-2012, 01:10 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Your echo is running before chkconfig completes. Try running the commands independently and you will see the difference. Your only option may be to place it in a bash script and do some tricky loop work to get the chkconfig command to complete before pulling the exit code.
 
1 members found this post helpful.
Old 04-09-2012, 01:40 PM   #3
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Original Poster
Rep: Reputation: 31
Hello Kustom42,
Thank you for your reply. It was my understanding that Bash waited for the first command to finish before running the second command. Is this not true?

Mike
 
Old 04-09-2012, 01:44 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Yes and no, the command has been issued successfully in bash's mind in this case and it moves on to the next. I have not run across this behavior in the past but I have heard others of running into similar issues with binary applications. I was able to get the correct response when replacing the pipe with a semi-colon to tell bash to issue a new command as opposed to piping it.
 
1 members found this post helpful.
Old 04-09-2012, 04:24 PM   #5
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Original Poster
Rep: Reputation: 31
DOG GONE IT!!!!!
That's what I'm doing differently..... a pipe instead of a ;
I knew there was something so simple but I could not figure it out.
See, this WAS, a while back, working for me. I was using a ; not a |.
Thanks again so much for your help. I'd been another 2 months kickin myself trying to figure that out.
I would, given this problem, be very interested in know why command1 is not really done before command2 is issued.
Do you have any ideas on how I might go about this. The ; will work for my needs but I think this is a good learning opportunity.
How might I be able to "watch" the processes running? I'm not even sure how to proceed figuring this out but I think it would be interesting.

Thanks again,
Mike
 
Old 04-09-2012, 04:45 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Well basically when you are piping commands you are telling bash to execute the command and move on, in most of our piped commands the execution will complete prior to the next command running. Think of it this way, say you wanted to run a perl application that took 2 minutes to complete and pipe the output to another command, once bash tells perl to execute the code bash's job is done and it considers the command to be executed and will move on to the next one and will not wait the 2 minutes for the job to complete. Bash considers the exit status of the perl command to be a 0 because perl took the code it gave it and started to run the process.
 
2 members found this post helpful.
Old 04-10-2012, 07:47 AM   #7
youngstorm
Member
 
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235

Original Poster
Rep: Reputation: 31
Ah! That makes sense. Thank you again for all your help

Mike
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C bool return values conventions tadeas Programming 1 10-30-2010 07:47 AM
chkconfig runs script with different PATH values dchester11 Linux - Server 3 10-07-2010 09:36 PM
Inconsistency in function return values Completely Clueless Programming 5 09-03-2009 09:12 AM
system() and return values PatrickNew Programming 1 02-07-2007 04:35 AM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 03:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:48 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