[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::korn_shell_programming

Title:Welcome to Korn_Shell_Programming
Moderator:PLUGH::needle
Created:Wed Jun 26 1991
Last Modified:Fri May 30 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:118
Total number of notes:426

118.0. "How to read and assign variables with KSH ?" by HANDVC::QA () Mon May 12 1997 04:14

    
    > ps -o ucomm,pmem,nswap,inblock,oublock,pcpu
    COMMAND          %MEM NSWAP INBLK OUBLK %CPU
    csh               0.3     0    14     8  0.0
    netscape          9.6     0  8143  6848  0.0
                       ^      ^    ^     ^    ^
                       |      |    |     |    |
    how do you write ksh script to read the above values and assign them
    to variables and then use them for calculation ?
    
    -Man
    
T.RTitleUserPersonal
Name
DateLines
118.1SPECXN::DERAMODan D'EramoWed May 14 1997 15:1322
        Maybe this small example will get you started...
        
        Dan
        
        
#!/usr/bin/ksh

ps -o ucomm,pmem,nswap,inblock,oublock,pcpu |&

n=0
while read -p command mem nswap inblk oublk cpu
do
    n=$((n+1))
    echo Line $n
    printf '    command = %s\n' $command
    printf '    mem     = %s\n' $mem
    printf '    nswap   = %s\n' $nswap
    printf '    inblk   = %s\n' $inblk
    printf '    oublk   = %s\n' $oublk
    printf '    cpu     = %s\n' $cpu
done
118.2NQOS01::lexser22.lex.dec.com::GingerRon Ginger, Unix ConsultantFri May 30 1997 18:441
use perl