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.

Filter by
Sorted by
Tagged with
0
votes
0answers
6 views

check remote open check with zabbix-agent

We want to check open port with Zabbix-agent. client node (Zabbix-agent) is a windows server. We use UserParameter in zabbix-agent.conf and set this command UserParameter=echo quit | c:\Zabbix\curl\...
0
votes
0answers
31 views

Using timeout to escape a command also stops the for loop it is inside

I have a script that uses the package airodump-ng to do some wireless monitoring. It iterates through a list of mac addresses and scans them. I am using timeout to send an exit code to airodump ...
0
votes
1answer
24 views

How to exit the parent script as failed when the child script fails

I have a script which calls another script. Now even if the second script fails it's still succeeding original script. Below is the first part of the script: #OBJ_TYP=`echo $Job_detail_corr | awk -...
0
votes
1answer
36 views

xargs does not quit on error

I have a bash script where I use find to get a bunch of files in a directory, from which I then use xargs to execute said files in a chroot environment 1 script at a time. My understanding has been ...
3
votes
1answer
63 views

How to fail on executing zero byte file?

If I have zero byte file and it is executable, it will just do nothing. Can I fail on such files, i.e. return some error message and/or return non-zero exit code?
4
votes
1answer
155 views

In bash, how can I retrieve the exit code of a subshell when using local

This question is close to others - Can I get the exit code from a sub shell launched with $(command)? However there are no solutions I've found that allows me to get an exit code from a sub shell ...
0
votes
1answer
13 views

Timing of rsync exit codes on receiver and sender side

I would like to remotely perform an operation upon a file after an rsync transfer like so: rsync [options] file dest && ssh dest some_program file This requires the file not to be opened ...
0
votes
0answers
48 views

How can I get exit status of subshell?

A classical example of piping: $ false | true $ echo ${PIPESTATUS[@]} 1 0 Same example run in a subshell and assigning results into a variable: $ process="$(false | true)" $ echo ${PIPESTATUS[@]} 0 ...
0
votes
1answer
62 views

How to capture stdout and sterr AND proper piped exit status in Shell command?

I want to be able to do the following: command 2>&1 | shell_script.sh "subject line" Where the stdout and sterr of running command will be piped to shell_script.sh for sending as the body of ...
0
votes
1answer
40 views

Ansible reporting “CHANGED” on “hostname”?

According to Ansible's own documentation: changed: A boolean indicating if the task had to make changes. Why then does a command to report hostname return a "changed" status? localhost:/Users/...
0
votes
1answer
38 views

Where to find a documentation on Apt return values on error?

I am looking for a list of all possible error return values in Apt (the package management tool in Linux). All I could find with man apt is: "Diagnostics apt-get returns zero on normal operation, ...
3
votes
2answers
80 views

Is it possible to use && operator in terminal command template loop?

I wanted to make a list of similar clear commands clearer to read, so I've made a little terminal loop for what in \ cache \ thumbs \ ; do my template $what:clear; done It works great, however ...
3
votes
1answer
62 views

grep vs zgrep exit status differences with multiple files

Setup echo "abc" >/tmp/foo1 echo "def" >/tmp/foo2 cp /tmp/foo1 /tmp/gzfoo1 cp /tmp/foo2 /tmp/gzfoo2 gzip /tmp/gzfoo* grep exit status with multiple files and one match is 0 grep -q abc /tmp/...
-1
votes
2answers
89 views

fsck exit status “System should be rebooted”

The fsck(8) manpage on Linux includes the following table of exit codes: The exit code returned by fsck is the sum of the following conditions: 0 No errors 1 ...
2
votes
1answer
315 views

try/finally with bash shell [duplicate]

I have these three lines: export bunion_uds_file="$bunion_socks/$(uuidgen).sock"; "$cmd" "$@" | bunion rm -f "$bunion_uds_file" I need to make sure the last line always executes..I could do ...
0
votes
1answer
93 views

How do I exit with a failure code if the wrong number of args are passed to my script?

I'm using bash. How can I exit with a non-success code if my script has the wrong number of arguments? I have this #!/bin/bash if [ "$#" -ne 3 ]; then echo "Should be three parameters to this ...
9
votes
2answers
1k views

How to loop for 3 times in bash script when docker push fails?

I have a bash script which simply docker pushes an image: docker push $CONTAINER_IMAGE:latest I want to loop for 3 times when this fails. How should I achieve this?
3
votes
1answer
135 views

Comparing exit code: unary operator expected [duplicate]

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. Depending on the result I want ...
0
votes
1answer
85 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 ...
2
votes
1answer
764 views

Redirections and Return Codes

So I have a program that may or may not segfault (./segf) that also writes other data to stderr. When the program segfaults, its return code is 139 (i.e. echo $? will print 139). I would like to ...
-1
votes
2answers
42 views

Why doesn't back-slash yield non-zero exit code

If run: true \ false; echo $? I get an exit code of 0. Does anyone know why that is?
0
votes
1answer
43 views

What happens when we run var=3 command [duplicate]

Below I run what I expected to be an invalid command: var=3 date, which in fact isn't. $ var=3 date Sun May 26 17:10:22 UTC 2019 $ echo $? 0 But the variable wasn't assigned the value 3: $ echo $...
0
votes
2answers
178 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 ...
4
votes
4answers
2k views

Bash - Execute two commands and get exit status 1 if first fails

In the case below, the report command must always be executed but I need to get an exit status 1 if the test command fails: test;report echo $? 0 How can I do it in a single bash line without ...
1
vote
1answer
154 views

Exit status of chained commands

I want to run a potentially invalid command in a variable cmd. I can't afford to have it just fail me and retrieve the exit status. What I can try to do is pipe it to : and then I'll have a successful ...
0
votes
3answers
264 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
2answers
208 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
1answer
399 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 ...
5
votes
1answer
221 views

How to make `trap` know if the EXIT is after successful program finish or because of premature as an error or something

PROBLEM: I have a shell program that I have been writing but I can't find out how to make sure that trap is trapping for cleanup at the end or because of a error in some command, it cleans up either ...
26
votes
1answer
1k views

Finding files for which a command fails

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?
4
votes
2answers
1k views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
1
vote
2answers
844 views

What is Linux exit status and list of all status

I'm trying to learn Linux bash scripting and I'm read through the articles in the http://tldp.org sites I saw some kind log clearing scripting I notice that something is used for as an exit status. I ...
0
votes
0answers
85 views

C++ script on Spark Cluster throws exit status 132

I'm trying to run a c++ program on spark cluster by using the rdd.pipe() operation but the executors throw: java.lang.IllegalStateException: Subprocess exited with status 132. The spark jar runs ...
4
votes
2answers
3k views

Bash Script Function Return True-False

I want to query the function by returning the value. My codes are as follows; check(){ file=/root/Turkiye.txt local funkx=$1 while read line; do if [ "$line" == "$funkx" ] ...
4
votes
1answer
116 views

Display output of `time` only if command after `time` was successful

I want the output of the time command to be shown only if the command, which has been passed to time was successful. Something like this: ( time wget -pq --delete-after https://www.example.com ) 2>...
4
votes
1answer
1k views

Failed to activate systemd-timesyncd.service

I've scanned all forums and questions and found no working answer to my problem. The Network Time Synchronization service doesn't work. The timedatectl service seems to work just fine without it ...
1
vote
3answers
3k views

Remote Command executed via ssh does not return proper return code. Return error code is always “0”, even condition failed

I am not getting proper exit return code during execution of remote script on a Linux machine. This script is intended for checking whether a user exists or not. My Script is below :- #!/bin/bash ...
0
votes
0answers
59 views

Is it possible to “coax” arbitrary core *nix utilities into returning a non-zero exit status even when successful?

I am running bash scripts and executing bash commands on remote systems using Connectwise Automate (formerly LabTech). These systems are both Linux and MacOS. Connectwise Automate (CWA) has some ...
1
vote
0answers
207 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. ...
0
votes
2answers
29 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 ...
4
votes
4answers
3k views

systemd status=127 for /usr/bin/install when trying to start MariaDB

I just upgraded my MariaDB installation to 10.2. When I now try to start the service, it tells me it failed an checking the status shows me this rather strange message: root@server # systemctl status ...
5
votes
3answers
2k views

bash script executed over ssh returns incorrect exit code 0

I am trying to automate a process which involves running scripts on various machines via ssh. It is vital to capture both output and the return code (for the detection of errors). Setting the exit ...
1
vote
1answer
86 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
5
votes
2answers
776 views

How to run multiple processes and exit if any of them exits or fails

I am running multiple processes and want to exit with the appropriate exit code (this means error on failure, success otherwise) if any of them fails or exists. Additionally if any child process ...
10
votes
5answers
3k views

Capture exit code of exit command

I have this in a bash script: exit 3; exit_code="$?" if [[ "$exit_code" != "0" ]]; then echo -e "${r2g_magenta}Your r2g process is exiting with code $exit_code.${r2g_no_color}"; exit "$...
0
votes
2answers
298 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 ...
2
votes
1answer
602 views

ldd equivalent which fail when library not found

Assume I perform ldd /bin/ls with the pthread library removed. I obtain linux-vdso.so.1 (0x00007ffcc3563000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000) libcap.so.2 => /...
0
votes
2answers
380 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
6k 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
35 views

Slackbuild script with “set -e” exit..at no error!

With this slackbuild: #!/bin/sh PRGNAM=libnfsidmap VERSION=${VERSION:-0.25} BUILD=${BUILD:-3} TAG=${TAG:-_mg} if [ -z "$ARCH" ]; then case "$( uname -m )" in i?86) ARCH=i486 ;; ...