stop Prstat using shell script

How to stop the Prstat using shell script ?
because after i run the below script the thing seems to be always in loop and cannot get out till i ctrl + c, is there anything that i can add in the script to make it terminate ?

<code>
#!/bin/sh

prstat -Tc -u testing > testing.txt
</code>

please help a noob ....

this prints one page

prstat  1 1

you can adapt more options to your needs

ok thanks... and btw... if i have lots of command for e.g.

<code>
prstat 1 1 > test1.txt
df -k > test2.txt
cat messages | grep abc > test3.txt
</code>

is there anyway i can put them all into separate txt files but can i put all the output into one file ? Please advise and thank you ghostdog for your help :slight_smile:

use ">>" instead of ">"

thanks once again ghostdog...

is there anyway i can write something into a file using a script ?

for e.g. i want to have a line break for the different input
and i want to input different words into the file

#!/bin/sh

line = "---------------------"
processes >> test1.txt
$line >> test1.txt
prstat 1 1 >> test1.txt
$line >> test1.txt

i've tried the above and it doesn't work can someone please guide me thanks
and btw is there any good website that i can refer to for such codings of shell?

you declare variable in shell with no spaces in between "="
eg

line="--------------"
echo $line >> file

must i echo them in order for the line to be in the file ?
by the way is there any good website for me to reference all these codes ?

yes.

Here

thanks ghost will read up first :slight_smile:

in a prstat there are so many values if i want to specifically pick one value and compare it, is it possible ?

In the above case i did a

prstat -Tc -u hellousr

then i changed to

prstat -Tc -u hellousr | grep 1

because i wanted to grep the taskid = 1 line and i am only interested in the CPU Usage value, 0.5%. However, when i do a grep 1 all the things are shown.

i need to do a if statement using script for it like
if CPU Usage for TASKID=1 > 0.5% , then it is known to be unhealthy else it is healthy.

sample of the prstat file

PID USERNAME SIZE RSS STATE PRI NICE TIME     CPU   PROCESS/NLWP
12  hellousr  77M  52M sleep   59  0      0:00:01 0.0% session_handler/12

TASKID NPROC SIZE  RSS   MEMORY TIME      CPU   PROJECT
1     12      563M 376M 9.9%      0:00:06  0.5% system
prstat -T -k 1 -n 1 -u user 1 1 | awk 'NR==4{print $7}'

ghost thanks for your constant help, but it doesn't print out anything...

it works already
but can you please explain abit on whats the
awk 'NR==4{print $7}'
i only knows that awk is a process and it extract out the 7th char base on print $7 how about the rest ?

on my system:

bash-2.03$ prstat -T -k 1 -n 1 -u root 1 1
   PID USERNAME  SIZE   RSS STATE  PRI NICE      TIME  CPU PROCESS/NLWP
    88 root     6944K 5592K sleep   59    0   0:00.01 0.0% picld/15
TASKID    NPROC  SIZE   RSS MEMORY      TIME  CPU PROJECT
     1       58  845M  260M   8.8%   0:13.57 0.0% system

TASKID appears on the 3 line, so what you want is at the 4th line, hence NR==4.
The CPU value is at field 7, hence $7.

Brilliant ! Thanks, You're the man !

date +%H%M --> this command will get the Hour and Minutes of the time

but how do i get year months and day ??? anyone have any idea ?

the first thing you should do is check the date man page.
%Y gives you the year....you should be able to find for months, and day.

oh yah why didn i think of that ! thanks sorry for the trouble people