Use this tag for questions on how to handle errors generated in shell scripts.
1
vote
2answers
65 views
Move directories despite of errors
When moving a directory to another drive, if there are errors in the process, nothing will be deleted. I am getting this kind of errors:
mv: cannot stat ‘originaldirectory/longpath/irrelevantfile’: ...
-2
votes
0answers
39 views
Unable to use apt-get commands Kali Linux | install and update not working (Not 'Unable to fetch package' error) [closed]
So I began to have trouble installing programs upon the first run of my new install of Kali 64-bit. The essence of the problem is the user is unable to use apt-get install, update, upgrade commands. ...
0
votes
2answers
31 views
How do I fix wget on an HTTP url not trusted errors in kali?
When I try to run the wget command on http urls I get this error message:
ERROR: The certificate of `url' is not trusted.
ERROR: The certificate of `url' hasn't got a known issuer.
-2
votes
1answer
27 views
Error installing anything on Kali 2.0
I changed from 32bit to 64bit and i cant install anything.
As soon as i installed the OS i used apt-get update and apt-get upgrade.
Now everything i try to install i get the following error.
Reading ...
3
votes
1answer
48 views
trap on command exit not working unless used in a function or sub-shell
Am experimenting a bit with trap on invalid command return code using a sample code
#!/bin/bash
# Exit on error
trap 'echo 'exiting..';exit' ERR
set -e
h=1
b=$((h+)) # <----- command causing ...
0
votes
1answer
32 views
How to define a function that handles `command not found`?
I'd like to define a function that is called, whenever a shell-user types a command that does not exist. In my case I'd like to log the errors and try alternative commands.
currently, when typing e.g....
1
vote
0answers
34 views
STDERR redirection without intermediate file
Here is a toy shell script:
#!/bin/bash
set -e
misspelled_command
exec > run_$( date +%Y%m%d ).log 2>&1
echo "Logging"
exit
If I submit with nohup bash raise_errors.sh > /dev/null 2&...
1
vote
3answers
45 views
Prevent grep from exiting in case of nomatch
This script does not echo "after":
#!/bin/bash -e
echo "before"
echo "anything" | grep e # it would if I searched for 'y' instead
echo "after"
exit
It also would if I removed the -e option on the ...
1
vote
1answer
44 views
/sbin/ldconfig.real: /usr/local/lib is not a known library type
I was following this instruction on this site to installing tesseract: https://github.com/tesseract-ocr/tesseract/wiki/Compiling
git clone https://github.com/tesseract-ocr/tesseract.git
cd tesseract
....
1
vote
1answer
56 views
Error trying to restart ssh
rookie linux user here. I am using Linux Mint 18, the same distribution I have been using most of the semester for school. I was tasked with making certain adjustments to the sshd_config file, ...
0
votes
2answers
52 views
Can't run the exe file [closed]
[I'm new to Linux, sorry]
So I have a code (.c file). And used the following command;
#!/bin/bash
#
gcc file.c -o file.exe
#./file.exe
So when I try to run the .exe file (using Wine) I get an ...
1
vote
1answer
137 views
What are the standard error codes in Linux?
When I write a code in bash for instance that copies a file, when the file doesn't exist, in the terminal I see an error similar to "file not found", if the script user isn't granted the permission ...
0
votes
1answer
51 views
“The specified directory 'media/fa/FAF9-!C03' is not valid” Error when trying to open USB sticks!
I have an ARM-based computer(nanopi m1) that has 3 USB ports that all work good with other devices like mouse, keyboard, wireless dongle. but when I try any USB flash memories it doesn't work!
What's ...
59
votes
2answers
6k views
Why is pattern “command || true” useful?
I am currently exploring Debian packages, and I have been reading some code samples. And on every line in, for example, the postinst script is a pattern.
some command || true
another command || true
...
2
votes
1answer
22 views
Fedora 15 updates
I have a dual booted system, and its been years since I have used the linux side. I am running Fedora15 and am trying to upgrade. I have tried
yum install preupgrade
and I get the error message
...
0
votes
1answer
82 views
Writing the output of a command to a file in a bash script
I am trying to write a simple bash script that executes the command tcprobe -i $1 where $1 is an mp4 file. Then, I want to write the output of this command, which should be a long string of ...
0
votes
1answer
45 views
apt vs apt-get error code
Strange thing I have here, when apt is locked by something. Respectively, the error codes don't match up. apt update seems to always return success 0, whereas apt-get update returns a proper error ...
0
votes
2answers
50 views
Running command multiple times and trigger report on failure
I am trying to run the "make" command on my project 100 times. But, obviously I wouldn't be monitoring the results but I would like to know when the build fails.
How would I go about making it ...
1
vote
0answers
20 views
Warn in crontab if command has failed multiple consecutive times
I have a command in my crontab to monitor a service (specifically, check whether the Tor version of my website can still be accessed): this monitoring command succeeds if it can access the site, and ...
3
votes
3answers
84 views
Apache not binding to port 80?
I am having issues with Apache. I just installed Centos and waant to create a webserver of my own. I am following the directions of "the perfect server for centos 7.2" and came upon this error on my ...
0
votes
2answers
114 views
Why “syntax error near unexpected token”? [closed]
I have about 10k (approx 180x50x2) CSV files which I want to join together as following, but the inner for loop fails because of some syntax error; I cannot see the error in lastFile
#!/bin/bash
dir='...
0
votes
1answer
53 views
Script error “fork: retry: Resource temporarily unavailable”.. will failing lines be retried?
I'm running a ping script that backgrounds ping calls.
#!/bin/bash
for ip in $(seq 100 210); do
ping x.x.x.$ip -c1 |grep "bytes from" |cut -d " " -f4|cut -d ":" -f1 &
done
If I receive ...
1
vote
1answer
51 views
Getting gcc piped-to-less to properly show colors on the terminal
I'm compiling a file with gcc (actually I'm make'ing, but never mind), which sends some colorized error messages to stderr. So, I do:
gcc a.c 2>&1 | less
but what I get is lines such as:
a.c:...
3
votes
2answers
53 views
How fix E: Sub-process /usr/bin/dpkg returned an error code (2)?
When I'm trying to use apt-get install or upgrade I get that message!
I tried this command sudo dpkg -C and got this results:
The following packages are missing the list control file in the
database, ...
0
votes
1answer
27 views
Error Update package ubuntu server
Hello i have this error when launch apt-get update command on my ubuntu server :
how can i solve this?
W: Impossibile scaricare alcuni file di indice: saranno ignorati o verranno usati quelli ...
0
votes
1answer
52 views
bash if condition on git command result
I have the following error due an invalid git command within my shell-script. git push blabla master results in fatal: 'blabla' does not appear to be a git repository
I would like to respond to ...
1
vote
1answer
98 views
How to repeat a command n times then exit?
I want to automate an installation and I need to run the downloaded installer with gksu. I have tried:
attempt=0
until
gksu command; do
attempt=$((attempt + 1))
if [ "$attempt" -gt 3 ]; ...
3
votes
4answers
2k views
How to exit a shell script if one part of it fails?
How can I write a shell script that exits, if one part of it fails?
For example, if the following code snippet fails, then the script should exit.
n=0
until [ $n -ge 5 ]
do
gksu *command* &&...
5
votes
3answers
89 views
How to get further information about the origin of an exit code?
Sometimes I need to maintain programs that invoke shell scripts which invokes other programs and scripts. Therefore, when the main shell script ends with exit code 126, it is a struggle to find out ...
1
vote
2answers
239 views
Halt the execution when something is written to stderr
I have trouble with error handling in bash scripts. None of the solutions I have seen for error handling in bash seem to work so far for this example script:
#!/usr/bin/env bash
set -euo pipefail
...
1
vote
2answers
161 views
I keep on getting a lots of error when doing sudo apt-get update. And it take a long time to complete
unique@my-pc ~ sudo apt-get update
[sudo] password for unique:
Err http://ppa.launchpad.net jessie/main amd64 Packages ...
0
votes
1answer
263 views
$? returns errorlevel 0 instead of 4
I just migrated a working Windows Batch script (.bat) to Unix Shell. Generally it's working quite nicely, however, I just realized that the errorlevel that is returned in Unix is wrong.
From what I'...
0
votes
1answer
41 views
Is there a way to highlight the part of the line where an error is happening
I'm running this script and getting an error like this, but am having extreme difficulty detecting where exactly the error is happening. Is there an option when it points out exactly what characters ...
-3
votes
1answer
71 views
How to Do Error-trapping and Swapoff if Error/Warning?
Pseudocode where incomplete pseudo try-catch after cas' comment
#!/usr/bin/env bash
# http://askubuntu.com/q/799834/25388
# Use: `sh myScript`; sudo does not work with Matlab.
#set -e # no ...
3
votes
2answers
209 views
How to Resolve the Insecure warning in Swapon?
I do
#!/usr/bin/env bash
# http://askubuntu.com/q/799834/25388
# http://stackoverflow.com/a/69808/54964
set -e
SWAP_FILE="/media/masi/SamiSwapVirtual/.swap_file_20.7.2016"
SIZE_MB=16000
dd if=...
1
vote
0answers
275 views
Mint 17.3: Your session has lasted less than 10 seconds
yesterday I executed 'sudo apt-get update && apt-get upgrade'
and today I get the following error after the login
Your session has lasted less than 10 seconds...
syndaemon: no process found
/...
1
vote
1answer
38 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 ...
1
vote
0answers
184 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
97 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 ...
2
votes
1answer
100 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
1answer
8k 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
413 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 ...
9
votes
4answers
768 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
1answer
173 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
63 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 all ...
-2
votes
2answers
816 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
21 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://foo....
1
vote
1answer
86 views
Catch unexpected input on single character read in bash [duplicate]
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
2k 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
104 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 ...