The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
3answers
74 views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
2
votes
1answer
81 views

YAD - Terminate Bash Script

I'm using YAD to create a Yes or No dialog box in a bash script: yad --image "dialog-question" --title "Alert" --button=gtk-yes:0 --button=gtk-no:1 --text "Are you sure you want to do this?" If I ...
5
votes
2answers
252 views

How do I look up exit codes for applications?

I'm having difficulty locating a comprehensive up-to-date list of error codes from Bash. e.g.: $ udevadm info /dev/sdx; echo Exit code $? Unknown device, --name=, --path=, or absolute path in /dev/ ...
1
vote
1answer
56 views

How do I get the exit code of a process, which runs through wine

I'm trying to run a Windows executable via wine. When I first try to run it never runs, but when I attempt to do it again, the program runs. I'd like to make a script to run the program, here's the ...
31
votes
4answers
2k views

Is there any UNIX variant on which a child process dies with its parent?

I have been studying the Linux kernel behaviour for quite some time now, and it's always been clear to me that: When a process dies, all its children are given back to the init process (PID 1) ...
2
votes
3answers
186 views

Should I embed a command in a conditional or test its return code?

It's a simple question of best pratices: Which should I use? Option 1 ping -c1 "$host" if [[ $? -eq 0 ]] ; then command else command fi Option 2 if ping -c1 "$host" ; then command ...
3
votes
2answers
101 views

exit a script if an ls line did not find any match

I am writing this script that have this line: ls -lrt /dir1/dir2/filename*.txt | tail -1 | awk '{print $9}' | read variable What I wanted is to exit the script (without using if-statement) if it ...
3
votes
3answers
178 views

New parent process when the parent process dies

In UNIX, when a parent process disappears, I thought that all child processes reset init as their parent. Is this not correct all the time? Are there any exceptions?
0
votes
2answers
57 views

Determining the exit status of the “return” built-in

I was reading about traps, but only return works for me in my shell script, so was wondering what status or code it returns, so what I tried is, #!/bin/bash seeOutput=`return` echo $seeOutput It's ...
1
vote
1answer
45 views

'script' session logging makes me exit twice

I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc: test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f ...
1
vote
1answer
45 views

Can Linux programs be sent a SIGXXX command they can respond to in the UI?

I am trying out the timeout command and would like to know if there is a kill signal that a GUI program, whether a graphics desktop or a terminal program will treat as the user terminating the program ...
2
votes
1answer
67 views

more command behavior

Someone can explain me about the more command? when I use it with || or with &&, it seems to have an exist status of true, even when the file is not found(Unlike the other commands). ...
1
vote
1answer
30 views

How do I obtain the kill signal / message / reason within a script?

I am using the following trap: trap OnExit EXIT And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
0
votes
2answers
593 views

Exit the bash function, not the terminal

I have a bash script as below which installs zookeeper but only if not installed already. ##zookeper installZook(){ ZOOK_VERSION="3.4.5" ZOOK_TOOL="zookeeper-${ZOOK_VERSION}" ...
2
votes
1answer
51 views

What signal does X send to its clients when it receives SIGINT?

If I terminate the Xorg server with a SIGINT signal (eg. when I press Ctrl+C), what signal does it send to its clients?
1
vote
1answer
154 views

How can I return a specific error code at this point in my TCL script?

I have a TCL expect script that runs a scp command for uploading a config file to my DNS server: #!/usr/bin/expect -f set config "~/dnsmasq.conf" spawn /usr/bin/scp "$config" ...
2
votes
3answers
2k views

How to copy or read the return value (exit status) from AWK script into the shell script (bash) to be used in if statement to compare

I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like: My script: #!/bin/sh awk -v ...
1
vote
3answers
98 views

How do I shutdown the system after a particular process exits

I am downloading some software; I can see the pid of the download process with top. Let's say it's 1001. How can I make it so that my computer shuts down after process 1001 exits?
7
votes
1answer
148 views

How do I capture the exit code / handle errors correctly when using process substitution?

I have a script that parses file names into an array using the following method taken from a Q&A on SO: unset ARGS ARGID="1" while IFS= read -r -d $'\0' FILE; do ARGS[ARGID++]="$FILE" done ...
3
votes
1answer
689 views

Unable to get the right exit code from a script

I have a script which connects to a remote server via SFTP and get some file from there. My script goes like this: /usr/bin/sftp USER@remote.server.com <<EOF lcd /dir1/dir2/dir3 cd ...
3
votes
0answers
888 views

Proper usage of EXIT & ERR traps in bash scripts [closed]

I'm working on a bash script and as I've been going I've learned about traps, signals, function return codes and other such features I've not previously used. I may be thinking about things ...
3
votes
5answers
3k views

What does exit 99 means?

I'm new to Unix. Just want to know what is exit 99 and why would one use it and what are the significance uses of it. For example, I'm using exit 99.
1
vote
1answer
164 views

How to get exit code of a parallel process launched by xargs?

I'd made a script for launching parallel rsync process: #! /bin/bash LIST=$1 DEST_DIR=$2 RSYNC_OPTS=$3 #echo "rsyncing From=$SRC_DIR To=$DEST_DIR RSYNC_OPTS=$RSYNC_OPTS" echo $LIST|xargs -n1 -d, ...
2
votes
3answers
124 views

Get exit status of a process over SSH

Not sure how to google this (I tried with some things and didn't get much) or how this is even called. This is my typical workflow: SSH to a server run something there and leave it running in ...
1
vote
1answer
2k views

How to exit out of the shell script successfully so that python subprocess think it is successfull exit? [closed]

Below is my shell script which simply execute a url like this http://example.com:8080/beat and parse the response and verify certain conditions on it. If that condition is met, then exit successfully ...
7
votes
5answers
223 views

Can a program next in a pipeline see the exit code of the previous program?

I would like to make a pipeline of Bash scripts like this prog1 | prog2 such that prog2 can see the exit code of prog1 and act differently based on that information. Is this possible?
6
votes
3answers
3k views

reliable return code of background process

Let's assume the following piece of bash code: foo > logfile 2>&1 & foo_pid=$! while ps -p$foo_pid do ping -c 1 localhost done wait $foo_pid if [[ $? == 0 ]] then echo "foo ...
2
votes
2answers
213 views

Why does procmail send a copy of an inbound message to sender if it encounters an exit code?

I have a very simple procmail process that takes an inbound email and redirects it to a script: LOGFILE=/home/foo/procmail-log VERBOSE=yes MAILDIR=/var/spool/mail/foo DEFAULT=/var/spool/mail/foo ...
0
votes
2answers
424 views

How do I get the list of exit codes (and/or return codes) and meaning for a command/utility?

Is there a way I can do what stated in the title from the terminal commands, or will I have to look into the codes?
17
votes
9answers
2k views

How to make sure that a command is not interrupted, even if terminal is closed? [duplicate]

In Linux. Say I want to run a command and it takes too long. I just want to ensure it's done. How?
3
votes
2answers
3k views

test if return true if grep on output has string in one line

I just want to return true or false if a service is running. Here is where I'm at, not first try or last but current at writing: service iptables status | grep -qi "not running" The sdtout for ...
0
votes
1answer
271 views

if env variable exists then exit out of script

#!/bin/bash if [[ -n "$MYVAR" ]]; then exit; fi # otherwise the rest of the script continues... I'm trying to exit out of a shell script if a certain ENV variable is 0. The script above does not ...
2
votes
2answers
1k views

Busybox ash script does not exit cleanly after executing cat; unable to get exit code

Consider the following script wrapcat.sh (a wrapper for cat) for illustrative purposes. It is run with busybox (ash) in an embedded Linux 2.6 box. #!/bin/sh cat $1 Under certain circumstances, this ...
3
votes
2answers
1k views

What is “Exit 2” from finished background job status?

I have an exercise to put in a file some data (*conf from some directories) and need to do this in background. I did it and I am wondering what is the meaning of output messages: [A@localhost tests]$ ...
0
votes
2answers
283 views

Test if number from range <0,infinity)

I have a problem If [[ * ]] then continue else exit 1 fi I want to test that the argument to my switch (for example -d 3) is a valid positive decimal integer number (a sequence of one or more of ...
2
votes
1answer
219 views

How to have a bash script perform a specific action on errors of _each_ command?

Similarly to set -e performs an exit on "uncaught" $? != 0, I'd like to have this event trigger the execution of another command, e.g. a logger call. How can this be done?
74
votes
4answers
1k views

Can I somehow add a “&& prog2” to an already running prog1?

Most shells provide functions like && and ; to chain the execution of commands in certain ways. But what if a command is already running, can I still somehow add another command to be executed ...
3
votes
1answer
685 views

How to trick an init script into returning 0

I have a init script which is poorly designed because it does not conform to the Linux Standard Base Specifications The following should have an exit code of 0 if running, and 3 if not running ...
12
votes
3answers
2k views

Wait command usage in Linux?

#!/bin/bash function back() { sleep $1 exit $2 } back $1 $2 & b=$! if `wait $!`;then echo success else echo failure fi bash-3.00# ./back 300 0 failure bash-3.00# ./back 300 1 ...
14
votes
2answers
561 views

Why does `exit &` not work?

I don't understand why exit & does not work. Why does it not?
1
vote
2answers
1k views

PHP exec command has the result 0 even if an error occurs

I have this PHP code: $execout=exec('ssh root@xxx.xxx.xxx.xx "sudo /etc/init.d/smokeping reload"',$output1,$result); if($result !=0){ echo"that can't reload"; } else{ echo "successfully ...
0
votes
2answers
2k views

Expect script within bash & exit codes

I have a bash script that calls an expect script. The expect script has several conditions. It ssh's into a box and executes a command, and there are different possible errors that could happen which ...
0
votes
2answers
229 views

Unix command to exit from command prompt

How can I exit from command prompt from shell file? shell file contains : if(); then // some unix code here else // want to exit from cmd prompt or Kill current cmd prompt fi can any knows @ it?
1
vote
0answers
2k views

Using sshpass, return code (exit status) differs for reasons unknown using valid commands

There are a few things going on here but I think ultimately, either CLish or SSH is returning an exit code that is messing up my work flow. I'm attempting to connect to a remote machine (CLish shell) ...
0
votes
1answer
772 views

ksh - map Ctrl-D to exit shell

I would like to know how we can map the keys Ctrl-D in ksh to exit the shell as it does in bash shell. Not much familiar with key binding in ksh. Edit My comments are after the <!-- string ...
5
votes
3answers
753 views

bash -e exits when let or expr evaluates to 0

I have a bash script that sets -e so the script will exit on any exit status != 0. I'm trying to do some basic shell arithmetic assigned to variables and sometimes the expression equals 0 which ...
2
votes
1answer
344 views

Exit status ($?) of 148 upon Ctrl+Z

I just customized my .bashrc to include the exit status of the last command, so I get fancy prompts like ☑ larsmans@host:~$ and I no longer have to re-run commands to see their exit status because ...
3
votes
1answer
1k views

Why won't my bash script exit after execution?

I compiled a short bash one-liner to focus a running application or launch it if it isn't running: #!/bin/bash #intellilaunch.sh wmctrl -a $1 || $1 & disown exit 1 The command exits perfectly ...
2
votes
2answers
110 views

Are any files loaded when a terminal session terminates?

I know that .profile / .bash_profile are loaded when a terminal session is started, either through local machine or SSH. Are there any files that are loaded/called when the session terminates? ...
3
votes
3answers
1k views

What does exit do in an if block in a shell script?

I have a question regarding unix shell script. Say if you do exit 1 in inner if: will it exit or will it still execute the outer if? The following is a dummy example. if [ "$PASSWORD" == ...