Sponsored Content
Top Forums Shell Programming and Scripting Exit Status within sudo su - $user Post 302218123 by quigley007 on Thursday 24th of July 2008 12:10:24 PM
Old 07-24-2008
Exit Status within sudo su - $user

I am having a problem reading the exit status of a command or script within a sudo.


Code:
return_code=99

sudo su - $User << EOF >> $output_file
$Script
return_code=$? 
exit $return_code
EOF

echo "return_code=$return_code"

returns
"return_code=99"

the $script above is a test script with a "exit 5" at the end. When I run it as the user and echo $? I get a 5.

I have been scanning the forums, trying my own stuff too, but cant seem to find the answer. How do I get the return code from the script (or command) passed out?

Thanks if you can help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies

2. Shell Programming and Scripting

Checking Exit Status

I hope one of you smart people out there can help me with what seems like a real simple questing but I can't quite figure out. In a script I am doing a cmp on two files. I am trying to check the exit status with an if statement but can't seem to figure out the syntax. If the exit status is 1 I... (4 Replies)
Discussion started by: PrimeRibAndADew
4 Replies

3. UNIX for Dummies Questions & Answers

exit status conditions

Hi all, i am writing a script to test if some servers are down and prompt if test positive. i used rlogin and rsh then exit but the script when run, logs into the servers and stays. pls what can i do to salvage this? or what other options do you suggest? (6 Replies)
Discussion started by: sdcoms
6 Replies

4. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

5. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

6. UNIX for Dummies Questions & Answers

$? = Exit status variable

hi, exit status variable $?, returns some digits. 0 ---> succes. 1..126 Failure (the program itself will decide what the numbers mean) 127 Command not found 128..254 The program did not exit normally. (E.g., it crashed, or received a signal) 255 Invalid exit code well, if $?... (4 Replies)
Discussion started by: dummydba
4 Replies

7. UNIX for Dummies Questions & Answers

service exit status

what are the number for the exit status for command service and what does every number mean. (2 Replies)
Discussion started by: programAngel
2 Replies

8. UNIX for Dummies Questions & Answers

Processes and exit status

Hi, I can't understand why the last $? is 1? can somebody plz help me to understand it? thanks $ ksh $ ps -f UID PID PPID C STIME TTY TIME COMMAND msarabad 12361 12319 0 15:17:58 pts/1 0:00 ksh msarabad 12319 12317 0 15:15:11 pts/1 0:00 -sh msarabad 12362 12361 ... (7 Replies)
Discussion started by: messi777
7 Replies

9. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

10. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies
S390_STHYI(2)							System Calls Manual						     S390_STHYI(2)

NAME
s390_sthyi - emulate STHYI instruction SYNOPSIS
#include <asm/unistd.h> int s390_sthyi(unsigned long function_code, void *resp_buffer, uint64_t *return_code, unsigned long flags); DESCRIPTION
The s390_sthyi() system call emulates the STHYI (Store Hypervisor Information) instruction. It provides hardware resource information for the machine and its virtualization levels. This includes CPU type and capacity, as well as the machine model and other metrics. The function_code argument indicates which function to perform. The following code(s) are supported: 0 Return CP (Central Processor) and IFL (Integrated Facility for Linux) capacity information. The resp_buffer argument specifies the address of a response buffer. When the function_code is 0, the buffer must be one page (4K) in size. If the system call returns 0, the response buffer will be filled with CPU capacity information. Otherwise, the response buffer's content is unchanged. The return_code argument stores the return code of the STHYI instruction, using one of the following values: 0 Success. 4 Unsupported function code. For further details about return_code, function_code, and resp_buffer, see the reference given in NOTES. The flags argument is provided to allow for future extensions and currently must be set to 0. RETURN VALUE
On success (that is: emulation succeeded), the return value of s390_sthyi() matches the condition code of the STHYI instructions, which is a value in the range [0..3]. A return value of 0 indicates that CPU capacity information is stored in *resp_buffer. A return value of 3 indicates "unsupported function code" and the content of *resp_buffer is unchanged. The return values 1 and 2 are reserved. On error, -1 is returned, and errno is set appropriately. ERRORS
EFAULT The value specified in resp_buffer or return_code is not a valid address. EINVAL The value specified in flags is nonzero. ENOMEM Allocating memory for handling the CPU capacity information failed. EOPNOTSUPP The value specified in function_code is not valid. VERSIONS
This system call is available since Linux 4.15. CONFORMING TO
This Linux-specific system call is available only on the s390 architecture. NOTES
Glibc does not provide a wrapper for this system call, use syscall(2) to call it. For details of the STHYI instruction, see the documentation page <https://www.ibm.com/support/knowledgecenter/SSB27U_6.3.0 /com.ibm.zvm.v630.hcpb4/hcpb4sth.htm>. When the system call interface is used, the response buffer doesn't have to fulfill alignment requirements described in the STHYI instruc- tion definition. The kernel caches the response (for up to one second, as of Linux 4.16). Subsequent system call invocations may return the cached response. SEE ALSO
syscall(2) Linux Programmer's Manual 2019-03-06 S390_STHYI(2)
All times are GMT -4. The time now is 05:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy