Questions tagged [exit-status]

Use this tag If your question revolves around determining or utilizing the exit status (return code) of a command. Common syntax involves the $? variable and the && and || symbols.

1
vote
1answer
709 views

exit status of command is different when it is run via strace

I can normaly mount/umount FTP as file system using following commands: └──> curlftpfs -o codepage=windows-1250 anonymous:anonymous@192.168.3.13 /home/marek/ftpfs └──> ls /home/marek/ftpfs/ 1 2 ...
1
vote
1answer
160 views

`ls` behavior on EACCES error for /root and /root/some-rubbish

I'm trying to code a clone of the ls command as part of a school exercise. I'm wondering why the following output is displayed by ls: $> ls -- -test_dir /root /root/some-rubbish ls: /root/some-...
1
vote
1answer
27 views

Tool to run a command until exit status is 0

Is there a tool that can accept a command and run it over and over until exit status is 0? I could probably check for value of $? in a loop but I wonder if there's a standard program for this
1
vote
2answers
41 views

Using the value of a variable as an exit code from a script

I can find plenty of information about how to assign the exit code of a script to av variable, but I want to do the opposite: use the value of a variable (defined within a script) as the exit code of ...
1
vote
1answer
72 views

Tracking child processes sequentially

I'm running few commands on a remote server, by sshpass. gnome-terminal --maximize --tab --title='aTask' -e "sshpass -p "afsd@#$5u89f" ssh root@192.168.0.125 'command1 && command2'" \ ...
1
vote
1answer
455 views

How can I generate my desired exit code on shell commands or one-line scripts?

I would like to generate some exit code, say 20. But if I do on shell: $ exit 20 the shell is closed (X-Windows case) or I am logged out (text console case). Of course, inside .sh scripts, this ...
1
vote
1answer
5k views

Script handling systemd service's return code

I'm writing a systemd service which can be started or stopped using systemctl commands. However this program can also return with several return codes and I would like to handle those return codes. ...
1
vote
1answer
2k views

Check for failure of piped command [duplicate]

Possible Duplicate: Get exit code of process that's piped to another If I pipe the output of one command into another, is there a way for me to check explicitly whether the first command ...
1
vote
2answers
1k views

Cron jobs monitoring using exit code

I want to monitoring cron jobs using shell script. But if I use variable contain exit code of last command I have "0" always. I think it's because I run this script after cron job and "exit code" ...
1
vote
1answer
2k views

How to get exit status of a background process?

I am running two mysqlsp in a bash script. I want to start both of them simultaneously (they are running in remote servers) and put them in background, once completed proceed to next step. I want to ...
1
vote
2answers
520 views

Trigger a non-zero exit code when I break out of a loop

I'd like to run a series of tasks but stop should any of them fail, hence I've written (something like): for task in [TASKS]; do process "$task" || break commit "$task" done This works fine, but ...
1
vote
1answer
230 views

Program exit when return in a function

This is a extract of my code: ninja () { if $1 = toto then return 1 elif $1 = tata then return 4 fi } main () { ninja "tata" if [ $? -ne 1 ] then somecode fi } main "$@" ...
1
vote
2answers
729 views

How can I disable xtrace and preserve my exit code

I'm trying to figure out a good way to disable xtrace before leaving a script. These are all being executed by Wercker, a continuous integration and deployment SaaS. A previous script of mine has run ...
1
vote
1answer
576 views

How can I pass the success (or failure) of a command to a variable?

I am running rsnapshot to do backups of my NAS. I am forwarding the output of the command (e.g. rsnapshot hourly, rsnapshot daily etc.) to /tmp/rsnapshot_stats_hourly. In another script, I'd like to ...
1
vote
1answer
218 views

Return code is always 0 after running echo “\$ macroName ” | ftp -i mymachine

I cannot seem to retrieve a non-zero return code when calling the ftp macro. It doesn't matter what errors are encountered during the ftp macro execution e.g. directory doesn't exist, file doesn't ...
1
vote
1answer
629 views

./a.out && echo $? only prints return value if return = 0

echo $? in the following scenario does not display the return value, i.e. 1. echo "int main() { return 1; }" > foo.c gcc foo.c && ./a.out && echo $? However, echo $? works when ...
1
vote
0answers
113 views

What does it mean when Duplicity exits with exit status 23?

I'm running Duplicity for backup of my desktop to a remote storage. Everything has been working fine, but now I see in my log that Duplicity has been exiting with exit status 23 for a couple of runs. ...
1
vote
0answers
69 views

Waiting for async console (message queue) output after invoking a command [closed]

I have to work with a command (lets call it update) which somehow prints its output asynchronously to the terminal (mq_timedsend). The output is not recognized as the commands output and therefore the ...
1
vote
1answer
205 views

Redirect YAD results into file AND still give exit codes from buttons to STDOUT

I have 2 custom buttons in my yad --form. The user input aka results get redirected into a .txt file for later use. Thats working fine. But it seems like the exit code is not given to STDOUT anymore, ...
1
vote
2answers
204 views

get pppd exit code - how?

I'm designing some reporting system on Raspberry Pi system which connects to world thru 3G usb modem controlled by pppd. 99,999% of time connection works ok, but sometimes it drops and further ...
1
vote
1answer
426 views

apt-get update failure returns 0 error code [duplicate]

When we run apt-get update and if it fails, a non zero error code should be returned, but in my case its still 0. See below: root@ubuntu-base:/home/user# apt-get update Err http://security.ubuntu.com ...
1
vote
1answer
657 views

How to get return value from MATLAB function

I am calling a MATLAB function with a bash script matlab -nodesktop -nosplash -nodisplay -r "matlabfunction input1 input2; quit" I am trying to get a one digit return value from the matlab function, ...
1
vote
0answers
113 views

How to find status of init.d exit scripts which return 0 on failure?

It seems that many init.d scripts return 0 on failure, in spite of these recommendations. For example, in nginx, running directly: /usr/sbin/nginx -t # returns 1 (with a bad config) and ...
1
vote
1answer
2k views

lftp return code

I have written below code to get listing from a remote server. echo "set xfer:log yes" > batchfile.txt echo "set xfer:log-file Templogfile1.txt">> batchfile.txt echo "open -p $rport -u $...
1
vote
0answers
58 views

How to capture “$?” before tee smashes it? [duplicate]

I've got a test script that repeatedly builds a library under different configurations. It also tee's the output for postmortem failures: $MAKE" static dynamic cryptest.exe 2>&1 | tee -a "$...
1
vote
0answers
550 views

whether the ssh command successful or not?

I spawned ssh in expect script. in the script i have to check the exit status of ssh command on local machine to make some condition in that script using if/else. spawn ssh user@192.168.1.1 ...
0
votes
2answers
99 views

how to know who is fail when doing ssh with test

Let's say I want to do some test VIA ssh example ssh 18.23.24.2 2>/dev/null "smartctl -a /dev/sdb -q silent" echo $? 1 in that case we get exit code 1 How to know if the problem is about ssh ...
0
votes
2answers
2k views

How to check for command exit code inside if statement

I'm trying to return a 0 exit code if a command exit with the a code 143 (timeout, from the "timeout command"), 1 otherwise. Due to external constraint (CI script), I have to start the command and do ...
0
votes
2answers
58 views

Exit status of last command using PROMPT_COMMAND

I want to save the exit status of the last ran command (in a file, in a variable, it doesn't really matter), but this must be done automatically in an interactive shell, manually running something ...
0
votes
2answers
2k views

ls error code 2

I was reading the man of ls and in the end it talks about the Exit status of ls. It says: Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if ...
0
votes
1answer
677 views

What exit code integer grep returns when it doesn't match a string?

What exit code integer grep returns when it doesn't match a string? I know it returns 0 when it does match and I assume it returns 1 when it doesn't. Is that correct?
0
votes
3answers
118 views

Why does finger not have a non-zero return value?

I often use the return/status value of a command in scripts. I'm curious why the finger command doesn't have a return value. E.g., $ finger kevin Login: klang Name: Kevin Kang etc......
0
votes
2answers
389 views

Does “rm -rf $dir” ever return false?

I've written the following line of code to delete the contents of a directory. rm -rf $dir && mkdir -p $dir However, this will not work if the first statement failed. Does it ever return 1?
0
votes
3answers
97 views

Handle specific error in bash

As a part of my script, I want to publish package to nuget feed: dotnet nuget push package.1.2.3.nupkg --source "mysource" --api-key "mykey" The command may print error: 409 already contains version ...
0
votes
1answer
124 views

exit status from rsync command

When I am executing rysnc command the exit status is 0, even though the command throws an error (code 23). I want to use the exit status code to terminate the script when there are no files found but ...
0
votes
2answers
27 views

Repeat command execution attempts until status is not specific, preserve data

I have a case where a first few command execution attempts after daemon restart are returning 2 (followed by stderr messages), than everything works correctly. In order to bypass this bug I've come ...
0
votes
1answer
57 views

New prompt line not automatically put to command line upon exit code

When submitting jobs, I'm getting Exit codes returned, but I have to hit the return key for them to be printed to the log. 1. prompt_line/location sas query.sas & 2. [1] 66682 3. prompt_line/...
0
votes
1answer
1k views

Exit status of sh command?

Hi I am calling a shell script from inside another shell script and if that script call goes successful I have to proceed further and I am using sh command to call another script like : sh payloadjob....
0
votes
1answer
122 views

Idiomatic bash way to run optional action without side effects on exit code

This script will exit with test result which is not desired from callers perspective. How it should be implemented instead? #!/bin/bash test -n "" && echo "test passed"
0
votes
1answer
8 views

Comparing exit code: unary operator expected

I have a list of git commits in a .txt file and I want to iterate over the commits. For each COMMIT_ID I want check them using a git command whose exit code is 0 or 1. Dependending on the result I ...
0
votes
1answer
17 views

atop died with exit status 53

I was running atop. It was working, but later it died with exit status 53. $ atop $ echo $? 53 Is this a bug in atop? Or is my system failing? Pre-emptive extra details :-) I checked in the ...
0
votes
2answers
85 views

Why echo$?' returns 0 even though 1 is expected? [closed]

For the following program, I get 0 for echo$? even though I expect 1. int main() { return 1; }
0
votes
2answers
179 views

BASH: how can I save the exit code in PS1 in order to use it later in PS1?

I am attempting to customize my PS1, in the following way (I have removed the colours): PS1='\u@\h:\w$(git_branch)$(useExitCode)\$ ' where git_branch() { git branch 2> /dev/null | sed -e '/^[...
0
votes
2answers
134 views

Using shell 'printf' where the format string is in a variable and doesn't have a fixed number of field placeholders?

I am writing a shell function which makes an external API call via cURL (the external API syntax isn't under my control). I've approached it like this (simplified): #!/bin/sh template_get_entry='...
0
votes
1answer
972 views

Return value error in bash scripts

I have bash script like this: rm ~/sqoop/"$TABLE"/* rmdir ~/sqoop/"$TABLE" return $? After execution this script it returns a value to next process but even though the script run successfully and ...
0
votes
1answer
130 views

Print variable inside loop

1. Summary I want to print variables from loop. If I place echo $i after command from loop:     Travis CI build passed. elif I place echo $i before command from loop:     I get exit code 1. I ...
0
votes
1answer
58 views

Perl: Error code returned to open3 after killed program

This program shows which error is returned to open3 when running either sleep 3 or true;sleep 3 and sleep is killed: #!/bin/bash ...
0
votes
2answers
1k views

Does postfix using mail command report if an email was unable to be sent to an address?

I am writing a program that will be sending external emails using postfix with the mail -s command and I need to verify that the email was sent to the specified address. In which case, I am curious ...
0
votes
2answers
3k views

return value of command not displayed in script

If I execute the below rsync command in command-line , I am getting the proper return status /usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime" echo $? ...
0
votes
1answer
1k views

Forwarding return value of shell script to C/C++ [closed]

I tried to find possible solution on Google, but all I found is explanation on how to return value, but not how to accept it in some programming language, in my case C/C++? Does anybody have idea on ...