LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-16-2014, 05:02 PM   #1
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Rep: Reputation: Disabled
Bash script exits, but doesn't exit


I have a Bash script that pings a website until it can reach it then launches My-Weather-Indicator. What I have works, but I can't get it to exit.

.run-mwi.sh contents:

#!/bin/bash
while ! ping -q -w5 -c1 www.google.com;
do
sleep 5
done
/usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator &
exit

The result using bash -x:

username:~$ bash -x .run-mwi.sh
+ ping -q -w5 -c1 www.google.com
PING www.google.com (74.125.239.116) 56(84) bytes of data.

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 12.458/12.458/12.458/0.000 ms
+ exit
username:~$ + /usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator
<gettext.GNUTranslations object at 0xb5385fec>
No LSB modules are available.
#####################################################
Distributor ID: Ubuntu
Description: Ubuntu 13.10
Release: 13.10
Codename: saucy
Version: i686
#####################################################

My-Weather-Indicator version: 0.6.5
#####################################################
/username/.config/my-weather-indicator/my-weather-indicator.conf True
Requesting timezone
############################################################
15:00 12:38 01:48
############################################################
WNW
############################################################
15:00 12:38 01:48
############################################################
WNW

And there it sits. My Weather Indicator is up, but I'm stuck in the script. Bash says it exits, THEN launches My Weather Indicator. If I Ctrl-C I can get out of it, and My Weather Indicator keeps running. What am I missing here?
 
Old 02-16-2014, 06:14 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,706

Rep: Reputation: 417Reputation: 417Reputation: 417Reputation: 417Reputation: 417
I would use:
Code:
exec /usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator
 
1 members found this post helpful.
Old 02-16-2014, 06:54 PM   #3
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thanks, but it didn't quite work. The difference I saw was that bash -x didn't show the 'exit' it did originally. Now, if I exit My-Weather-Indicator from the toolbar the script exits back to the prompt.

Quote:
Originally Posted by metaschima View Post
I would use:
Code:
exec /usr/bin/python3 /opt/extras.ubuntu.com/my-weather-indicator/bin/my-weather-indicator
 
Old 02-16-2014, 08:02 PM   #4
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,706

Rep: Reputation: 417Reputation: 417Reputation: 417Reputation: 417Reputation: 417
So you want the terminal to close ? I don't understand.
 
Old 02-16-2014, 10:16 PM   #5
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
No, I just need the script to finish. Do its thing and finish.

Quote:
Originally Posted by metaschima View Post
So you want the terminal to close ? I don't understand.
 
Old 02-16-2014, 10:28 PM   #6
cgrady357
LQ Newbie
 
Registered: Nov 2013
Posts: 5

Rep: Reputation: 1
If I understand correctly, I believe you want to run it as a background job. Put an & at the end of the command.
 
Old 02-16-2014, 11:28 PM   #7
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Ah, I thought of that too. Didn't work. All the usual things nohup, exec, &, etc. don't work. I've never seen anything like it. I even looked for BOM stuff and struck out. It just doesn't make sense. It's such silly little script and yet I can't get it to finish.

Quote:
Originally Posted by cgrady357 View Post
If I understand correctly, I believe you want to run it as a background job. Put an & at the end of the command.

Last edited by Jake7; 02-17-2014 at 12:13 AM.
 
Old 02-17-2014, 12:54 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,174

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Exactly why do you think your shell didn't finish? Did you use 'ps' to check it?
 
Old 02-17-2014, 03:09 AM   #9
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,773

Rep: Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039Reputation: 2039
If you hit Enter instead of Ctrl-C does it return the prompt?

From what you have shown you are simply getting the output from your weather command.
 
Old 02-17-2014, 02:42 PM   #10
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Yes, ps -e shows that My-Weather_Indicator is running and Bash is running.

Quote:
Originally Posted by NevemTeve View Post
Exactly why do you think your shell didn't finish? Did you use 'ps' to check it?
 
Old 02-17-2014, 02:53 PM   #11
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Hitting Enter does nothing. I agree this is obviously output from MWI, but is it coming from the background? Because I can't get a prompt I'm guessing it's still in running in front even though I've tried using &. I'm using the same script with Dropbox and it's working fine. When Google can be pinged Dropbox loads and the script exits back to the prompt. This one though. Damn! I even tried rewriting it by hand and saving it as under another filename without success. It still does the same thing.

What I don't get is why does bash -x say the script is already exited before starting MWI? If it's exited the script how is it launching MWI?

Quote:
Originally Posted by grail View Post
If you hit Enter instead of Ctrl-C does it return the prompt?

From what you have shown you are simply getting the output from your weather command.
 
Old 02-17-2014, 03:06 PM   #12
rtmistler
Senior Member
 
Registered: Mar 2011
Location: Milford, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 1,690
Blog Entries: 8

Rep: Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652
I have a couple of problems here:
  1. Why do you have #!/bin/bash - this should show as #!/bin/sh
  2. What's the output of ls -l /bin/sh for your machine?
  3. Is that output generated by having placed a set -xv line after the first line in your script? My concern here is that the +exit shows before the python call and that should not happen, it doesn't match the order of your script at all.

Can you post your script as coded within [code][/code] tags.

Please add the line set -xv as the second line of your script and post the output within [code][/code] tags.
 
Old 02-17-2014, 05:18 PM   #13
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,524

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by rtmistler View Post
  1. Why do you have #!/bin/bash - this should show as #!/bin/sh
Not all Linux distros associate /bin/sh with bash. Some distros, such as Ubuntu, associate /bin/sh with dash. Not all features of bash are available when using dash. It is quite plausible that the OP is specifying /bin/bash with the explicit intent of ensuring that his script uses bash.

Suffice to say, I would argue that using /bin/sh is NOT the proper syntax to use, especially for a script that will be used on multiple dissimilar Linux and/or Unix systems.
 
Old 02-17-2014, 08:55 PM   #14
Jake7
LQ Newbie
 
Registered: Feb 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
1) I use #!/bin/bash to insure that I'm invoking Bash.
3) In the OP you'll find the script and output. Also notice I ran the script using bash -x, which debugs the entire script. I didn't use set -x because it's a tiny script and I wanted to make sure I caught everything. Please refer to the OP.

Thanks!

Quote:
Originally Posted by rtmistler View Post
I have a couple of problems here:
  1. Why do you have #!/bin/bash - this should show as #!/bin/sh
  2. What's the output of ls -l /bin/sh for your machine?
  3. Is that output generated by having placed a set -xv line after the first line in your script? My concern here is that the +exit shows before the python call and that should not happen, it doesn't match the order of your script at all.

Can you post your script as coded within [code][/code] tags.

Please add the line set -xv as the second line of your script and post the output within [code][/code] tags.


---------- Post added 02-17-14 at 06:55 PM ----------

Exactly! Well said! Thanks!

Quote:
Originally Posted by dwhitney67 View Post
Not all Linux distros associate /bin/sh with bash. Some distros, such as Ubuntu, associate /bin/sh with dash. Not all features of bash are available when using dash. It is quite plausible that the OP is specifying /bin/bash with the explicit intent of ensuring that his script uses bash.

Suffice to say, I would argue that using /bin/sh is NOT the proper syntax to use, especially for a script that will be used on multiple dissimilar Linux and/or Unix systems.
 
Old 02-18-2014, 12:00 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,174

Rep: Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574Reputation: 574
Guess you should examine if the problem is specific to this Waether-whatever, or happens every time you start a background process in a script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash script exits halfway ? roycejp Linux - Newbie 2 11-04-2013 02:53 AM
"exit" in bash .bashrc procedure/shell function exits xterm anonguy9 Linux - Newbie 11 07-13-2011 04:54 PM
bash - setting a persistent variable that remains after the script exits CJ Chitwood Programming 9 01-24-2009 08:48 PM
Log what exits in bash script. What causes exit code thats not 0? Trailsmoke Programming 2 09-25-2008 04:07 AM
Flagging exits in Bash Script dtheorem Programming 5 11-08-2003 11:15 PM


All times are GMT -5. The time now is 02:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration