LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   shell code help please (https://www.linuxquestions.org/questions/linux-general-1/shell-code-help-please-755286/)

themanwhowas 09-15-2009 03:11 AM

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

acid_kewpie 09-15-2009 03:22 AM

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.

lutusp 09-15-2009 05:28 AM

Quote:

Originally Posted by themanwhowas (Post 3683256)
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

themanwhowas 09-16-2009 01:27 AM

Thanks guys. Very helpful.

linuxraja 09-16-2009 08:50 PM

Quote:

Originally Posted by themanwhowas (Post 3683256)
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

rahulruns 09-18-2009 04:12 AM

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


All times are GMT -5. The time now is 08:04 AM.