LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-24-2006, 12:45 PM   #1
Lobais
Member
 
Registered: Jan 2004
Location: Denmark
Distribution: Fedora Core 6
Posts: 224

Rep: Reputation: 30
Thread groups in bash?


Hi, in bash you can run two commands at the same time, using c1 & c2, but what if you want to run c3 only when c1 and c2 are finished?

Is that possible in bash or will it require a real programming language?
 
Old 04-24-2006, 04:55 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
You could sleep it while testing any condition like exit code OK, exists PID, exists pidfile.
 
Old 04-25-2006, 12:37 AM   #3
Lobais
Member
 
Registered: Jan 2004
Location: Denmark
Distribution: Fedora Core 6
Posts: 224

Original Poster
Rep: Reputation: 30
I see your point, but how do you test for such things in bash? Is there a command, that gives you exit code from a process number or such?
 
Old 04-25-2006, 08:31 AM   #4
merchtemeagle
Member
 
Registered: Oct 2004
Location: Belgium
Distribution: Slackware 13.37
Posts: 512

Rep: Reputation: 31
(c1 & c2) && c3
 
Old 05-03-2006, 12:30 PM   #5
Lobais
Member
 
Registered: Jan 2004
Location: Denmark
Distribution: Fedora Core 6
Posts: 224

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by merchtemeagle
(c1 & c2) && c3
Sadly, if I run for excample (sleep 4 & echo hi & echo test) && echo end. Bash prints hi, test and end instantly. Not waiting for the sleep.

I've made a very simple pythonscript for the purpose:
Code:
import sys, os, time, threading
from threading import Thread

class commandThread(Thread):
    def __init__(self, command):
        self.command = command
        Thread.__init__(self)
    def run(self):
        os.system(self.command)

for command in sys.argv[1:]:
    thread = commandThread(command)
    thread.start()
    
while threading.activeCount() > 1:
    time.sleep(1)
You run it like
Code:
./scriptname.py "echo hi" "echo test"; echo end
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
groups (system default groups) Xavius Linux - General 2 07-18-2012 02:50 AM
Map Windows NT Groups to UNIX Groups - why? kenji1903 Linux - Networking 4 10-16-2007 11:52 AM
How to run Bash scripts like thread in Java? nguyenzoro Linux - General 1 11-11-2005 02:08 AM
a thread about bash ... again andresv Slackware 2 04-19-2005 12:18 PM
winbind: wbinfo -g only lists global groups from PDC and not local groups saradiya Linux - Networking 0 12-01-2003 02:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:53 PM.

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
Open Source Consulting | Domain Registration