Programming :: Bash - Using Exit Status For Decisions
Mar 3, 2010How exactly can I use the exit status of a command in an if statement ?
Something like this:
Code:
How exactly can I use the exit status of a command in an if statement ?
Something like this:
Code:
I am running a command pretty similar to the one below:
Code:
I need to capture the exit status of that part of the command.
What I am trying to do is set a variable that can be modified within my_job.sh, and used to exit.
However, no matter what I set "status" to in my_job.sh, it exits with "0".
What can I do differently?
I have a scenario where I am executing some child shell scripts in background (using &)through a master parent script.
Is there a way I can capture the exit status of each individual child script after the execution is completed.
I'm new to scripting and I have a trouble with if statement syntax. The code is: Code: #there is a diff command here, and it does what i want but#i wanna see 1 if the exit value of diff is 0, and otherwise i wanna see 0.#the problem is here: (syntax error near unexpected token "then")
if["$?"==0];
then
echo 1
[code].....
Is there a way to count the number of errors- an exit variable $? from one function?
The output from the exit variable (either erroneous or correct (1) or (0)) is it possible to add the erroneous one ups?
I have not been able to write bash to use a PID file to ensure no other instance of the same script is running! All three methods I can think of to see if the PID in the PID file is another instance of the script make the script exit with a return code of 1 but the same commands run at the command prompt work as expected.
The first attempt was:
Code:
The first attempted workaround was:
Code:
The second attempted workaround (with debug to make the following command prompt copy and paste meaningful) was:
Code:
Here's the command prompt session, testing with a stale PID file and then manually running the problem command and it behaving as expected:
Code:
This on Slackware64 13.1 which has bash 4.1.7.
In desperation I tried rebooting but the behaviour was the same.
I am trying to get bash script using zentity to exit if the user presses the cancel or close buttons.The exit codes are working fine; they read 1 or 0 depending on the status but it always assumes 0. This is the portion of the script: PHP Code:
function settings(){
result=$(zenity --height=30 --width=300 --list --checklist --title='Selection'--column=Boxes --column=Selections --column="Options"
[code]...
I am new to scripting and been working on this bash script for awhile now. I been researching this problem, but I can't seem to find a solution. I was wondering if someone could please help me out. Here is my script:
#!/bin/bash
NO="ps -ef | grep NO | grep -v grep"
NOWC=`ps -ef | grep NO | grep -v grep | wc -l`
[code].....
I cannot get this script to run the "ps -ef" command on the client. It get its value from the host machine that I am running this script from. I need this command to execute on the client. When I run the command (ps -ef | grep NO | grep -v grep) on the client, I get something back. Here is what I get when I try to debug the script.
XX# ./test_ps5.sh XXXXX
+ NO='ps -ef | grep NO | grep -v grep'
++ ps -ef
[code]....
I noticed that if I have "exit" in a bash script file., e.g. script.sh,that when the word "exit" is reached, and the script file being executed is not in the PATH nvironment, i.e. ". script.sh", the whole konsole shell profile is exited! What gives here? Is there another command compatible to "exit" to prevent this, or will I just have the leave the "." part in the PATH enviroment, which is, to my understanding, is not recommended? I desire for a "goto" function in bash script files
View 11 Replies View RelatedI was installing SMPLAYER when the power failed...now i get this error message when trying to re-install the packages..
E: liblzo2-2: subprocess installed post-installation script returned error exit status 2
E: mplayer-nogui: dependency problems - leaving unconfigured
E: mplayer: dependency problems - leaving unconfigured
[code]....
In linux, creating thread is same as process (clone()), except the virtual address space gets shared with the parent.If a running main process(thread) creates new thread, and if main thread exits, why should the new thread too exit? both are different entities, The same doesn't happen if the child thread exits, the parent thread would be alive.
View 1 Replies View RelatedI'm getting the following output when trying to compile my cpp project:
Code:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/walther/NetBeansProjects/CppPlay'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppplay
[Code].....
I've seen you guys replying to others about this collect2 error, but all of them had some kind of informative message from the compiler.
Can't boot into Ubuntu. Using recovery mode, I get fsck exit with status 3 error. I did man on fsck and there is no reference to status 3. Same issue as [URL]
I have my data on sdb3 which is having this issue. File system is ext4. I can't go into shell or anything, I get the fsck error and the system reboots right away and stuck in that loop.
command will just execute and exit with a status of "0" -"Every command returns an exit status (sometimes referred to as a return status ). A successful command returns a 0, while an unsuccessful one returns a non-zero value that usually may be interpreted as an error code. Well-behaved UNIX commands, programs, and utilities return a 0 exit code upon successful completion, though there are some exceptions."[URL]With the command . . .
Code:
# dosfsck -v /dev/sdb
it could be very helpful (and decide my next move) to see the exit code as 0, 1, or 2 . the man page suggests the command exit code will specify if the message I get - "Cluster size is zero" (I think it is a "1")is a recoverable or fixable error by the utility. or is non-recoverable - a pretty nifty feature if I understand this right. [URL] is there anything like this script COMMAND_LAST used in the following link. [URL] that can be entered in the terminal window after - or at end of - my dosfsck command or any command. just to see if it has a 0, 1, or 2 status ?
I am making a project learning about inheritance and polymorphism
it consists of
Account.h
Account.cpp
[code]....
I'm running Ubuntu 9.10 Karmic and XBMC Live.I get error messages which seem to relate to openvpn.So I tried to remove it with the remove command. This is what I getQuote:
@XBMCLive:/home$ sudo apt-get remove openvpn
Reading package lists... Done
Building dependency tree
[code]....
"E: backuppc: subprocess installed post-installation script returned error exit status 1"whenever I upgrade my system I get the above message Anyone know how to fix it? or if it's anything important ?
View 1 Replies View RelatedI am trying to extract a .tgz file. I have used the command tar - xvwzf filename.tar but I get the following error:
gzip: stdin: decompression OK, trailing garbage ignored
tar: Child returned status 2
tar: Exiting with failure status due to previous errors
root@test:/datastore/Newfolder# tar -xvwzf filename.tgz
I'm trying to make a fresh install on my desktop computer and I got this error on boot:
Code:
udevd-work[155]: '/sbin/modprobe -bv pci:<followed by some numbers>'
unexpected exit with status 0x0009 and it stuck there.
Note that I'm trying to install from a usb stick.
I have CentOS 5.5 x64 here and I've been trying to build this RPM but I have found no way to get passed this error. RPM build errors: Bad exit status from /var/tmp/rpm-tmp.61655 (%prep)
View 12 Replies View RelatedI am using a fully updated fedora 13 64-bit system and when i run make on xoscope i get the following error:
collect2: ld returned 1 exit status
I have already installed all of the prereqs. And the configure went without errors.
My system has stopped to boot at all...
Code: Select alldone.
Setting parameters of disc: (none).
Setting preliminary keymap...done.
Activating swap...done.
Checking root file system...fsck from util-linux-ng 2.17.2
[Code] ....
An automatic file system check (fsck) of the root filesystem failed. A manual fsck must be performed, then the system restarted. The fsck should be performed in maintenance mode with the root filesystem mounted in read-only mode. ... failed!
The root filesystem is currently mounted in read-only mode. A maintenance shell will now be started. After performing system maintenance, press CONTROL-D to terminate the maintenance shell and restart the system. ... (warning).
Give root password for maintenance
(or type Control-D to continue): _
For now, I just don't know what I should to do next to my system has started to work again...
it's a hot day and nothing seems to be going right. Trying to figure a way out of this one - error 127. Looks like it could be Metacity problem? There a couple of pythons that also have a problem.
Code:
(Reading database ... 145089 files and directories currently installed.)
Preparing to replace metacity-common 1:2.28.0-0ubuntu1 (using .../metacity-
[code]....
I have been having the worst time trying to get sametime messenger from IBM to install properly. I had it working fine for the last 6 months and yesterday I accidently updated and it all went to {1134}. I seem to have found dkms to be the source of the problem.
I get an exit 0 regardless of whether or not its install or uninstall. I have managed to get pidgin to work for now, but it is no means ideal for my purposes.
I kept getting this...
rastlosen@rastlosen-laptop:~$ sudo apt-get install sametime-connect
[sudo] password for rastlosen:
Reading package lists... Done
Building dependency tree
[Code]...
Everytime I install a package or use update manager I get the following message.
Code:
E: linux-image-2.6.32-22-generic: subprocess installed post-installation script returned error exit status 2
E: linux-image-2.6.32-23-generic: subprocess installed post-installation script returned error exit status 2
E: linux-image-2.6.32-24-generic: subprocess installed post-installation script returned error exit status 2
E: linux-image-generic: dependency problems - leaving unconfigured
E: linux-generic: dependency problems - leaving unconfigured
E: linux-headers-2.6.32-22-generic: subprocess installed post-installation script returned error exit status 2
E: linux-headers-2.6.32-23-generic: subprocess installed post-installation script returned error exit status 2
E: linux-headers-2.6.32-24-generic: subprocess installed post-installation script returned error exit status 2
E: linux-headers-generic: dependency problems - leaving unconfigured
The install/upgrade appears to work but I'm getting concerned about the message continuing for so long.
I'm using ubuntu 10.10 maverick, a package named lmodern is not required by the system, but it can't be remove or purged as follow:
Code:
yurippe@Neptune:~$ sudo apt-get autoremove
Reading package lists... Done
[code]....
I am preparing everything that I will be using in my fourth year project which is based on the grid computing concept. My problem is that before I installed ubuntu 10.10, I was using 9.10. And in my previous version (9.10) I was able to install condor through the synaptic package manager comfortably,but after upgrading to version 10.10 am getting the following error after installing condor:
"E:condor:subprocess installed post-installation script returned error exit status 127"
I have a desktop environment with Apache2.(If someone asks why desktop to run Apache2, its because the desktop must display a local website)When I update the html files from a windows box it is being copied in a home/user folder.Cron now has to copy the files with r to the localhost area.sudo cp -R home/myself/Downloads/* /var/www/ works fine:The script containing just that one line is in a file in my /home/myself/Documents folder named: copy_site_localhost.Cron entry in turn was created with the command: sudo crontab -e and the entry is:*/10 * * * * /home/myself/Documents/copy_site_localhostThe error in the syslog file in /var/logs is as follows:
.......CRON[1234] (root) CMD (home/myself/Documents?copy_site_localhost)
.......CRON[1236] error (grandchild #1234 failed with exit status126)
.......CRON{1236] info (No MTA installed, disregarding output)
[code]....
I am having a terrible time getting any networking to work with a new RedHat Enterprise 6 64 bit install. I am installing on an HP Proliant DL380G7.I have downloaded the driver - hp-netxtreme2-6.2.23-2.src.rpm from the HP website.Followed directions and did the following:1.Build Environment Setup - installed redhat-rpm-config and kernel-devel2.Installed the source (hp-netxtreme) rpm.3. Build the Binary RPM - installed rpm-build and ran the following:rpmbuild -bb /root/rpmbuild/SPECS/hp-netxtreme2.specIt runs through the build process and near the end I get the following:make -C /lib/modules/2.6.3271.el6.x86_64/build UBDIRS=/root/rpmbuild/BUILD/hpnetxtreme26.2.23/obj/default/bnx2-2.0.23b/src modulesexpr: syntax erromake[2]: Entering directory '/usr/src/kernels/2.6.32-71.el6.x86_64'/usr/src/kernels/2.6.32-1.el6.x86_64/arch/x86/makefile:81: stack protector enabled but no compiler supportmake[2]: gcc: command not found
make [3]: ***[/root/rpmbuild/BUILD/hp-netxtreme2-6.2.23/obj/default/bnx2-2.0.23b/src/bnx2.o] Error 127make[2]: ***[_module_/root/rpmbuild/BUILD/hp-netxtreme2-6.2.23/obj/default/bnx2-2.0.23b/src] Error 2make[2]: Leaving directory '/usr/src/kernels/2.6.32-71.el6.x86_64'
[code].....
i have a problem and it's been persisting since i installes MST Core fonts.
terminal log is here:
-----------start of pasting -----
user@Ubuntu9:~$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
code....