LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-17-2013, 10:54 AM   #1
mahendra singh
LQ Newbie
 
Registered: Mar 2011
Location: Bangalore,INDIA
Posts: 12
Blog Entries: 1

Rep: Reputation: 0
Command execution order


Appreciate for the fast reply

Dear Friends,

I have a script which has 2 commands in it.
Command 1 takes long time to do its job.

ex:

vi t.ksh

#bin/bash
grep "m" *.txt ---command 1
grep "t" *.ksh ---command 2


Is there a way that i don't wait the completion of command 1 in script and script proceed with next execution of command.?

Regads,
Mahendra Singh

Last edited by mahendra singh; 08-17-2013 at 10:56 AM.
 
Old 08-17-2013, 11:20 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Yes, append at end of command "&". It will send this process to background.
Code:
#!/bin/bash
grep "m" *.txt &
grep "t" *.ksh
 
Old 08-17-2013, 11:31 AM   #3
mahendra singh
LQ Newbie
 
Registered: Mar 2011
Location: Bangalore,INDIA
Posts: 12

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Quote:
Originally Posted by eSelix View Post
Yes, append at end of command "&". It will send this process to background.
Code:
#!/bin/bash
grep "m" *.txt &
grep "t" *.ksh


I did but its still throwing the output on console for first command?
 
Old 08-17-2013, 11:52 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by mahendra singh View Post
I did but its still throwing the output on console for first command?
the obvious question is: would redirecting the output to a file help ?
 
Old 08-17-2013, 02:41 PM   #5
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
And what you want to do with the output of first command?
 
Old 08-17-2013, 04:11 PM   #6
reza_zah1991
Member
 
Registered: Mar 2013
Location: Qom , Iran
Distribution: opensuse,lubuntu
Posts: 32

Rep: Reputation: Disabled
Thumbs up

Code:
reza@reza-HP-1000:~$ cat /etc/passwd |grep 'root' &>file &
[1] 5636
reza@reza-HP-1000:~$ cat file 
root:x:0:0:root:/root:/bin/bash
[1]+  Done                    cat /etc/passwd | grep --color=auto 'root' &>file
with >&file you send the stdout & stderr to a file

and with the & at the end of the line you send the process to the background

if you have problem with lastLine,,youcan read the file & delete the last line with sed command
 
Old 08-18-2013, 09:35 AM   #7
mahendra singh
LQ Newbie
 
Registered: Mar 2011
Location: Bangalore,INDIA
Posts: 12

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Hi All,

Yes issue got resolved, I have put the first process or command background(&) and the next command got executed.

Thank you
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cron jobs execution order chicken76 Linux - Newbie 2 04-20-2013 06:16 AM
What is the correct order of execution of "login" config scripts? lucky7456969 Linux - Newbie 1 09-09-2012 08:35 AM
Saving state/ensuring order/one time execution in functional languages Sergei Steshenko Programming 2 06-30-2012 01:06 PM
How to set the SGE job execution order cliffyao Linux - Newbie 1 10-16-2010 10:46 PM
Only execute 2nd command on successufl execution of 1st command kregec05 Linux - Newbie 3 08-19-2009 10:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 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
Open Source Consulting | Domain Registration