LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 03-20-2010, 07:39 AM   #1
vandana
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Rep: Reputation: 0
A script called by another script would always give exit status other than Zero(0)


Hi all

i m trying to execute 1st script into other script. I want the 1st script to put the exit staus into a log file .Also i want to ensure that 1st script will always give exit status other than Zero.Also i want to add text in log file.Like
if(success)then
echo "success:" exit status
if (failure) then
echo "failure:" exit status

Please help as i new to shell scripting.
Thanks
Vandana
 
Old 03-20-2010, 08:17 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Your requirements are a bit unclear to me. Could you please explain what you want in more detail? What's the purpose of these two scripts and the relationship between them? How do you intend to call the second script from the first? How about some example code or pseudocode?

In general though, the exit status of a script is that of the last command it executes. Use the "exit" command to control what code is issued when the script exits (for example, add "exit 1" to the end of the script to make it output a status of 1). Finally, "$?" is used to get/output the exit status of the previous command.

"echo xyz >> filename" can be used to append lines to a file.
 
Old 03-22-2010, 04:26 AM   #3
vandana
LQ Newbie
 
Registered: Mar 2010
Posts: 2

Original Poster
Rep: Reputation: 0
To put exit status of a script into a log file

Quote:
Originally Posted by David the H. View Post
Your requirements are a bit unclear to me. Could you please explain what you want in more detail? What's the purpose of these two scripts and the relationship between them? How do you intend to call the second script from the first? How about some example code or pseudocode?

In general though, the exit status of a script is that of the last command it executes. Use the "exit" command to control what code is issued when the script exits (for example, add "exit 1" to the end of the script to make it output a status of 1). Finally, "$?" is used to get/output the exit status of the previous command.

"echo xyz >> filename" can be used to append lines to a file.

Thanks David
now its working the way i wanted it.
 
  


Reply



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
Shell script: can you tell if a script is called via an alias? BrianK Programming 11 10-01-2009 11:16 AM
How can I get exit status from a called shell. dthacker Programming 4 06-27-2008 09:51 AM
how to pass a variable from a called script back to the calling script steven.c.banks Linux - General 2 05-05-2008 02:00 PM
call another script and have the inital script exit mjtice Programming 1 09-11-2005 11:54 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM

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

All times are GMT -5. The time now is 03:44 PM.

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