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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-08-2012, 07:19 PM
|
#1
|
Member
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235
Rep:
|
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.
|
04-09-2012, 01:10 PM
|
#2
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
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.
|
04-09-2012, 01:40 PM
|
#3
|
Member
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235
Original Poster
Rep:
|
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
|
|
|
04-09-2012, 01:44 PM
|
#4
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
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.
|
04-09-2012, 04:24 PM
|
#5
|
Member
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235
Original Poster
Rep:
|
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
|
|
|
04-09-2012, 04:45 PM
|
#6
|
Senior Member
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604
|
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.
|
04-10-2012, 07:47 AM
|
#7
|
Member
Registered: May 2003
Location: USA
Distribution: Fedora 21, RHEL 5,6&7, Windoze 7
Posts: 235
Original Poster
Rep:
|
Ah! That makes sense. Thank you again for all your help
Mike
|
|
|
All times are GMT -5. The time now is 08:48 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|