Help Writing a C Shell Script

Hi Everyone,

I need a script that will do the following...

1) Begin monitoring user, process activity on the server.

2) Print the number of monitoring cycle you are on(i.e. the loop
number of monitoring ).
Print the current number of users running on the server.
Print the current number of processes running on the server.
(use ps -a , don't use -e . )

3) Wait one minute before you monitor the users, processes again.
Repeat step 2) fifteen times.

4) After step 3) is done:
- print the smallest and largest number of users during monitoring.
- print the smallest and largest number of processes during monitoring.


It seems like a pretty simple script, but I've never programmed a shell script, only C++ code. How would I go about doing it? And does anyone know the best place to learn to write c shell scripts online? Thanks, a lot!

Comments

  • : Hi Everyone,
    :
    : I need a script that will do the following...
    :
    : 1) Begin monitoring user, process activity on the server.
    :
    : 2) Print the number of monitoring cycle you are on(i.e. the loop
    : number of monitoring ).
    : Print the current number of users running on the server.
    : Print the current number of processes running on the server.
    : (use ps -a , don't use -e . )
    :
    : 3) Wait one minute before you monitor the users, processes again.
    : Repeat step 2) fifteen times.
    :
    : 4) After step 3) is done:
    : - print the smallest and largest number of users during monitoring.
    : - print the smallest and largest number of processes during monitoring.
    :
    I struggle to see C as a scripting language. :-) You'd be far better off using a language that you can call a scripting language more easily. If you know C/C++, you should be able to get to grips with Perl pretty easily. FYI, here's a Perl script that'll do something like what you want for number of proccesses (users is for you to do... ;-)).

    [code]#!/usr/bin/perl

    my $minps = 99999999; # If you got more than this...whoa...
    my $maxps = 0;

    for (1..15) {
    # Get number of proccesses.
    my $ps = `ps -a | wc -l` - 1;

    # Store min and max numbers.
    $minps = $ps if ($minps > $ps);
    $minps = $ps if ($maxps < $ps);

    # Print out and wait 60 seconds.
    print "$_ :: Proccesses = $ps
    ";
    sleep 60;
    }

    # Print min and max numbers.
    print "Proccesses: Min = $minps Max = $maxps
    ";
    [/code]

    FYI, ps -a | wc -l returns the number of proccesses + 1.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : I struggle to see C as a scripting language. :-) You'd be far better off using a language that you can call a scripting language more easily.

    I believe he meant [b]csh[/b] (aka C shell) scripting.
  • : I believe he meant [b]csh[/b] (aka C shell) scripting.
    LOL...so do I now I bother to read it properly. ;-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories