*nix - useing the DO statement

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

*nix - useing the DO statement

Post by Cuda68 »

I am trying to monitor a process on a PID or process, lets say mozilla-firefox, whatever. I would like to execute this at the command line where it would run every 15 minutes or so to give me an update on its progress. I have gotten this far but I am stuck with it not working.

[cuda@localhost ~]$ while loop
> do
> ps -ew | grep mozilla-firefox
>
>
> done
bash: loop: command not found
[cuda@localhost ~]$


Any ideas on how to make this work, I know it missing the time to repeat because I don't know what it is.
User avatar
heftig
DBB Ace
DBB Ace
Posts: 138
Joined: Mon Jun 05, 2006 9:55 pm
Location: Germany
Contact:

Post by heftig »

If the script is doing something completely automated and you don't need to watch it i'd recommend using the chronograph service (cron). Fully automatic execution at specified times or intervals without user intervention.

If you need to watch the script's output, use the \"watch\" program.

Code: Select all

watch -n 1 \"ps -ew | grep apache2\"
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

Post by Cuda68 »

yea, but it controls the session. I only have n amount of sessions and was looking to set it in the back round. It will do the job though if I cant get the statement right.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6530
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

Are you trying to do an infinite loop? Try:

Code: Select all

while [ true ]
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

Re:

Post by Cuda68 »

Jeff250 wrote:Are you trying to do an infinite loop? Try:

Code: Select all

while [ true ]

Yes that's it woohoo, now I need to put a timer control on it. like making it run once or twice every 15 minutes to give me an update until the process quits.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6530
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

You can put a delay in the loop with:

Code: Select all

sleep 15m
or something analogous. Look in sleep's man pages for usage.
Cuda68
DBB Captain
DBB Captain
Posts: 745
Joined: Mon Jul 09, 2001 2:01 am
Location: Denver, CO USA
Contact:

Post by Cuda68 »

yipper that's it, I just found it myself finally on Google.

Thanks alot for the assist, I am learning Perl scripts at work by being thrown into the fire. I did buy some books by Oreilly to help myself along but I am in the very beginning of learning. In a way this is so very cool and at the same time sucks. :o

:P
Post Reply