LinuxQuestions.org
Visit Jeremy's Blog.
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 09-15-2009, 03:11 AM   #1
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, Fedora 23
Posts: 218

Rep: Reputation: 29
shell code help please


Hey,

2 questions regarding the shell.

1 - In a shell script i want several apps to run successively. ram1.pl, ram2.pl, ram3.pl etc. I've tried "./ram*" but that just ran the first script and stopped. Is there a way i can run these without typing them all out in the script?

2 - i want to get the output of 'time perl.pl' into a file. i tried 'time perl.pl > time.txt' but that didn't work. I tried echo `time perl.pl` > time.txt which also failed. I assume there is a way. Any help please?


Thanks
 
Old 09-15-2009, 03:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
1)
for i in ram*
do
$i
done

2) the first way will work, unless it is being written to stderr instead of stdout. does changing > to 2> make a difference? If so, the code needs to be changed to use stdout properly.
 
Old 09-15-2009, 05:28 AM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by themanwhowas View Post
Hey,

2 questions regarding the shell.

1 - In a shell script i want several apps to run successively. ram1.pl, ram2.pl, ram3.pl etc. I've tried "./ram*" but that just ran the first script and stopped. Is there a way i can run these without typing them all out in the script?

2 - i want to get the output of 'time perl.pl' into a file. i tried 'time perl.pl > time.txt' but that didn't work. I tried echo `time perl.pl` > time.txt which also failed. I assume there is a way. Any help please?


Thanks
1.

Code:
for fn in *.pl
do
   ./$fn
done
You asked for "successively". For simultaneous, do it this way:

Code:
for fn in *.pl
do
   ./$fn &
done
2.
Code:
/usr/bin/time -o time.txt ./perl.pl
The problem you were having with the second command arises from the fact that there are two "time" commands -- one a Bash builtin, the other a standalone with more features. This information comes to light by ... reading the manual.

Code:
$ man time
 
Old 09-16-2009, 01:27 AM   #4
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, Fedora 23
Posts: 218

Original Poster
Rep: Reputation: 29
Thanks guys. Very helpful.
 
Old 09-16-2009, 08:50 PM   #5
linuxraja
LQ Newbie
 
Registered: Sep 2009
Posts: 17

Rep: Reputation: 0
Quote:
Originally Posted by themanwhowas View Post
Hey,

2 questions regarding the shell.

1 - In a shell script i want several apps to run successively. ram1.pl, ram2.pl, ram3.pl etc. I've tried "./ram*" but that just ran the first script and stopped. Is there a way i can run these without typing them all out in the script?

2 - i want to get the output of 'time perl.pl' into a file. i tried 'time perl.pl > time.txt' but that didn't work. I tried echo `time perl.pl` > time.txt which also failed. I assume there is a way. Any help please?


Thanks

try ./ram* &

that should work (i think!)

linux

Last edited by linuxraja; 09-30-2009 at 09:55 PM.
 
Old 09-18-2009, 04:12 AM   #6
rahulruns
LQ Newbie
 
Registered: Feb 2008
Posts: 21

Rep: Reputation: 0
Run the code

while ((flag != 1))
do
ram1.pl &
pid1=(ps -ef | grep ram1.pl | grep -v "grep")
ram2.pl &
pid2=(ps -ef | grep ram2.pl | grep -v "grep")
ram3.pl &
pid3=(ps -ef | grep ram3.pl | grep -v "grep")
ram4.pl &
pid4=(ps -ef | grep ram4.pl | grep -v "grep")
if [[ -z "$pid1" && -z "$pid2" && -z "$pid3" && -z "$pid4" ]];then
flag=1
fi
done
 
  


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
help to explain the shell code ! nillgump Linux From Scratch 1 10-11-2008 11:09 AM
Semaphore-like shell code omnio Programming 13 03-12-2007 03:36 AM
shell scource code??? akshay_jp Linux - General 3 11-05-2005 09:46 PM
c code vs shell script again? khucinx Programming 1 05-12-2004 09:44 PM
c code vs shell script? khucinx Programming 1 05-12-2004 06:06 PM

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

All times are GMT -5. The time now is 07:30 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