Use this tag for questions on how to handle errors generated in shell scripts.
1
vote
1answer
12 views
Ldap error doesn't redirect to file
I'm running a loop querying ldap server for a single dn every time, just to see if it's running okay. I want to output both the successful and unsuccessful responses to a file and while the former ...
0
votes
0answers
12 views
Error calling EVIOCSKEYCODE
I used journalctl -p 3 -xb
and got this error message
-- Logs begin at Thu 2016-06-23 22:48:08 AST, end at Sat 2016-06-25 13:15:23 AST. --
Jun 25 09:31:35 Almoullim systemd-udevd[268]: Error calling ...
0
votes
2answers
43 views
Skip catching errors in a shell script
I have a script which compile a program. This program first compiles the source code using configure && make commands, then runs some tests using make test. This script also uses set -e to ...
0
votes
0answers
24 views
wlan0 and wlan1 are active but they cannot detect the Wifi Network!
My wlan0 and wlan1 are active after I installed the compat wireless 2016-26-10. They cannot detect the wifi network. I have a dual boot and when I use the same in Windows, I can detect the signal but ...
2
votes
1answer
35 views
Echo input text amount limit?
I'm trying to do
echo "foo
foo
foo
....[many many lines of foo here]
foo" > "/Users/myname/destination.txt"
through Applescript, but it returns an error when the characters in the lines of foo ...
1
vote
0answers
29 views
How to make “sudo” command work? [closed]
I tried to change symbolic links of libz files in lib64.
Previously it was:
libz.so.1 -> libz.so.1.2.3
Now it is:
libz.so.1 -> libz.so.1.2.7
When I try to use sudo and change it back, i ...
0
votes
1answer
262 views
blk_update_request: I/O error, dev fd0, sector 0
I recently started noticing some blk_update_request: I/O error, dev fd0, sector 0 errors on my second computer running Arch Linux that I use as a server. This began when I had to reboot the computer ...
2
votes
4answers
52 views
How to catch and handle nonzero exit status within a Bash function?
Say I have the following (pointless) Bash function:
myfunc() {
ls
failfailfail
uptime
}
I run it as follows:
myfunc || echo "Something is wrong."
What I want to happen is ls runs (as ...
8
votes
4answers
586 views
Bash program not executed if redirection would fail
In bash, I notice that if a command using redirection would fail, any programs which run prior to that are not run.
For example, this program opens the file "a" and writes 50 bytes to file "a". ...
4
votes
2answers
106 views
Silent disk errors and reliability of Linux swap
My understanding is that hard drives and SSDs implement some basic error correction inside the drive, and most RAID configurations e.g. mdadm will depend on this to decide when a drive has failed to ...
1
vote
1answer
53 views
trap errors in bash scripts
I have several questions I want to understand in regards to error trap.
why does the code below execute only 1 trap and not 2 and specifically only the code with "mydir2" and not "mydir1"?
why at ...
-2
votes
2answers
130 views
Print out a log file with error from a cp command
I am writing an sh file
I have this command
cp test/*.txt NewDirectory/
from my understanding it will go one by one
in the test folder
1.txt
2.txt
5.txt
6.txt
but won't copy
3.txt
4.txt
...
0
votes
0answers
18 views
Redirect stderr to stdout and tee to file and check return value [duplicate]
I know how to redirect stderr and stdout to a file:
curl -sSo file http://foo.bar >> log 2>&1
I know how to get stdout to appear on the console and in a file:
curl -sSo file http://...
1
vote
1answer
65 views
Catch unexpected input on single character read in bash
I have a bash script, which, at one point asks the user for confirmation. I do this by reading a single character, which is then transformed to lower case and checked if it is 'y'. If not, the script ...
0
votes
1answer
745 views
What does ESRCH mean?
Out of:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
It's always pretty clear why an errno code is named a particular way except for this one.
How does SRCH relate to No such ...
2
votes
1answer
43 views
Error exit script from within command substitution
If I have a function:
myfunction() {
[ -d somedirectory ] && [ "some other condition" ] || { echo "error" >&2 ; exit 1; }
global_var=somevalue
}
And I call it from within another ...
19
votes
6answers
1k views
How can I suppress output only if the command succeeds?
I would like to simplify the output of a script by suppressing the output of secondary commands that are usually successful.
However, using -q on them hides the output when they occasionally fail, so ...
1
vote
1answer
261 views
Bash script to select files to zip/unzip
I'm trying to zip and unzip files with a bash script, but I'm new and I have problems. I will explain what the script currently does, and then what I wanted it to do.
User selects “compress”: a file ...
2
votes
1answer
31 views
how to differentiate error returned while reading and for EOF in shell script
I have this task of uploading a delimited file and processing it. Once the processing is done, i either say its successful and if parsing fails, i need to throw the error. I'm reading this file line ...
0
votes
0answers
18 views
redirect all errors of my script into errors.txt [duplicate]
I need to redirect all errors into other file which called errors.txt.
This is my script shell :
data_in=$1
fichier=$2
cd $data_in
#Purge des fichiers
rm -f Split/INIT_ENC.dat
rm -f Split/...
0
votes
0answers
13 views
Labeling error messages
When dealing with errors, utilities often print their name followed by the error message, for example, sed, cat, awk, etc.
sed: foo: No such file or directory
Others print the word fatal, followed ...
1
vote
3answers
461 views
Debian live iwlwifi firmware error
When booting Debian live onto my computer, I encountered the errors:
[ 19.456064] iwlwifi 0000:03:00.0: firmware: failed to load iwlwifi-7265-9.ucode (-2)
[ 19.456183] iwlwifi 0000:03:00.0: ...
1
vote
2answers
174 views
What's the most efficient way to log crontab shell script errors with error occurred time?
A common way to log crontab task errors looks like below:
1 */8 * * * sh /pseudo_path/test.sh 2>> my_err_log
It's a concise command, but it can't record the error occurred time, and the path ...
3
votes
2answers
145 views
Simultaneously check for empty output and successful exit status
I'd like to write the following test in an installer script1:
if [ -n "`/etc/grub.d/30_os-prober`" ]; then
install_dual_boot
else
install_linux_only
fi
However, it's also possible that ...
0
votes
3answers
6k views
apt-get update failed to fetch and /sources.list.d/ empty
Running the sudo apt-get update command, I got the following error:
Fetched 988 kB in 16s (59,3 kB/s)
W: Failed to fetch http://old-releases.ubuntu.com/...
0
votes
1answer
30 views
Warning message after updating
I have Linux Mint 17 Cinnamon edition and after updating using the terminal:
sudo apt-get && sudo apt-get upgrade
I got this warning message:
...
Building dependency tree
Reading ...
1
vote
2answers
1k views
Capture errors in a SFTP script
I have a sub sh file which puts receives an input of local directory and path to the remote directory and sends the file to the remote directory. If the remote path is invalid the error cannot be ...
1
vote
1answer
43 views
Print nth pipeline command in bash
In bash, the PIPESTATUS array holds the return values of commands in a pipeline.
Suppose that in the pipeline cmd1 | cmd2 | cmd3, the second command returns an error. Checking PIPESTATUS gives the ...
1
vote
1answer
1k views
Shell script `rm -r`: Redirect write-protected prompt and answer “n”
I have a few lines in a shell script whose function is to iterate through directories, match some names, and delete them. Some areas of the file system are write protected and I would like to leave ...
-1
votes
2answers
363 views
Why to set errno to zero at the time of initialization of the program and can't test it before error occurred? [closed]
I am reading the material available on errno variable of <errno.h> header file.
I read :
" A value of 0 indicates that there is no error in the program." and "As a good practice, developer ...
4
votes
2answers
255 views
Is there a way to have a function in my bash script auto run on any command error?
I'm writing a shell script that needs to do a bunch of commands and every command depends on every previous command. If any command fails the entire script should fail and I call an exit function. I ...
1
vote
0answers
958 views
Repeated error : #error “Only <glib.h> can be included directly.”
I have a research on author attribution compression distance. And I should use "Complearn" ,which is a compression program, in my work. But in the beginning I have problem in installing this program.
...
1
vote
1answer
472 views
open() return new file descriptor posix [closed]
I have to set the return values for open() in posix. How do I return "the new file descriptor" as it is said in the Linux man pages:
RETURN VALUE
open(), openat(), and creat() return the new ...
2
votes
1answer
831 views
How to get non-zero exit code from Puppet when configuration cannot be applied?
I've tried the following Puppet configuration to disable the root password:
class users {
user { 'root':
password => '*',
}
}
But after applying it with no warnings or error messages I ...
2
votes
4answers
465 views
Mute system error message in a script file and display mine
I have created a simple script to move all the files with .sh suffix in the current working directory to a designated directory
If there was no such file, the script should output only an error ...
3
votes
1answer
343 views
How to make dd fail if it invalid skip value is specified?
When I invoke dd with an invalid value for skip it prints an error message and does nothing, but doesn't return with a value different from 0, e.g.
$ cd /tmp
$ mkdir xy
$ cd xy
$ truncate -s 2M test....
4
votes
2answers
226 views
Shell script error handling while assigning STDOUT to variable
I am trying to implement error handling in my shell script as described in the 2nd answer in Best practice to use $? in bash?
My script looks like this:
#!/bin/bash
try() {
"$@"
code=$?
...
1
vote
1answer
406 views
TCL script try catch
I have a TCL script that sets a number of variables and reads several files. The last file it reads may contain sensitive information, so I need to make sure this file gets deleted even if an error ...
4
votes
3answers
579 views
why bash increment: `n=0;((n++));` return error? [duplicate]
n=0;
((n++));echo "ret=$?;n=$n;"
((n++));echo "ret=$?;n=$n;"
((n++));echo "ret=$?;n=$n;"
from n=1 on, ((n++)) works correctly,
only when n=0, ((n++)) return error,
and I am using a trap '' ERR that ...
3
votes
1answer
252 views
Errtrace and local
I am using the following script:
#!/bin/bash -Eu
trap 'echo Hi' ERR
exit_failure() {
echo "Hello, World!"
return 1
}
sub_failure() {
res=$(exit_failure)
}
sub_failure
It results in the ...
3
votes
2answers
370 views
bash 'nounset' on sub-shell/child doesn't force main script to exit, how to workaround that globally?
With this script: tstNounset.sh
#!/bin/bash
set -x
set -o nounset;set -u
echo `echo $str`
function FUNC1() { echo $str; };export -f FUNC1;bash -c FUNC1
function FUNC2() { set -u;echo $str; };export ...
0
votes
1answer
376 views
Using trap with ERR: How do I send $?
In bash 4.x If I have:
err_handler() {
echo You received error $1|mail -s "script error" MAILTO
}
trap err_handler ERR
how do I send the actual stderr output to the function when the trap is ...
8
votes
3answers
549 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 &...
0
votes
2answers
1k views
Stopping .bashrc without exiting shell
My .bashrc file is modularized and I've got some error checking in it. In bash scripts, I typically have a function _errexit (or something similar) that I call when I detect an error and want to exit.
...
5
votes
0answers
4k 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
1answer
646 views
Strange error (?) when I run `man` command from a folder that no longer exists
Let's have a look at the followings:
radu@Radu:~$ mkdir test
radu@Radu:~$ cd test
radu@Radu:~/test$ rmdir ~/test
radu@Radu:~/test$ man ls
man: can't change directory to '': No such file or directory
...
7
votes
2answers
18k views
How to check whether a command such as curl completed without error?
I am using curl to upload a file to a server via an HTTP post.
curl -X POST [email protected] server-URL
When I manually execute this command on the command line, I get a response from the server like ...
7
votes
2answers
624 views
Making sure a command has executed in bash
I have a bash file with commands to merge pcap files. I want to know if there is anyway to make sure a line in bash runs or not. Like in windows bat file we have %ErrorLevel% ¨
Say a command
touch -r ...
12
votes
3answers
8k views
chmod + silent mode + how force exit code 0 in spite of error
Is it possible execute chmod and ignore error from command
Example ( remark file.txt not exsist to show the example )
When I type
chmod 777 file.txt
I get error on the output
chmod: cannot ...
5
votes
2answers
710 views
How to implement logwatch functionality on top of systemd journal?
Logwatch scans logfiles with regular intervals, collects errors and stuff, then mails it to the admin. This was back in syslog and logfiles days. What's the corresponding solution for systemd's ...