How to ask...???


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to ask...???
# 1  
Old 09-26-2001
How to ask...???

Thanks for checking in.

Do you know how too let this script ask me which program i want to check.

eg
$ "command"
$ echo "Monitor processes for which program"
$ output....
Code:
#Checking processes
ps -ef |grep fglgo > f1
cat f1 |cut -c 1-8 > a.1
cat f1 |cut -c10-14 > b.1
paste a.1 b.1 > B
cat f1 |cut -c49-72 > c.1
paste B c.1 > final
echo "STARTING TO CHECK"
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
cat final |more
rm f1
rm a.1
rm b.1
rm c.1
rm B
rm final

maybe substituation right in the begining will help.

2nd Script
Code:
PN=`basename "$0"`                      # Program name
VER=`echo '$Revision: 1.2 $' | cut -d' ' -f2`

# Determine mail spool directory (BSD/SYSV)
for MailDir in /tmpx
do
    [ -d "$MailDir" -a -r "$MailDir" ] && break
done

Usage () {
    echo >&2 "$PN - show top 10 directory users, $VER (hs '94)
usage: $PN [directory ...]

If no directory is specified, $MailDir is the default."
    exit 1
}

[ $# -gt 0 -a "$1" = "-h" ] && Usage

# set the default directory
[ $# -lt 1 ] && set $MailDir

echo "NAME                     BYTES    FILES   PERCENT"
ls -lL "$@" |
    awk '
        (NF == 8 || NF == 9 ) {                 # BSD or SYSV
            # example of a line:
            # -rw-------  1 andrea     286282 Oct 21 11:24 andrea
            #           or
            # -rw-------  1 andrea entw  286282 Oct 21 11:24 andrea
            Usage [$3] += $(NF-4)       # used bytes, username is index
            Count [$3]++
            TotalBytes += $(NF-4)
        }
        END {
            for ( user in Usage )
                printf "%-15s %12d      %d      %2d\n", \
                    user, Usage [user], Count [user], \
                    Usage [user] * 100 / TotalBytes
        }
    ' | sort -nr +1 | head
exit 0

same with this one how do i let this script ask me which dirrectory i would like to take a look at.

At the momment it only checks /tmpx

Thanks in advance
Marcus

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 11:37 AM..
# 2  
Old 09-27-2001
Well, to ask a questions, and record the answer in memory, use the "read" builtin command. Here's an example (I wrote it in sh instead of ksh, since I don't know which you're using, if either- this should be portable between the two, with the exception of the echo statement):

Code:
#!/bin/sh
# Simple example to read in a line, then echo it out

# If you're using Linux, you'll need to use "echo -e"
# instead of "echo".

echo "Enter a string: \c"

# The \c tells echo not to add a new line

read input

# That's where it takes your input and stores it into the 
# variable "input" - you can name this whatever you want

echo "\nThe \$input variable was: $input"

# The "\n" forces echo to insert a new line at that spot

Of course this script isn't of much use to anyone, but it gives an example of using read.
Hope that helps.
# 3  
Old 09-27-2001
Thanks allot this realy helped, you have no idea.

FINAL SCRIPT if you are interested

#!/bin/sh
# Simple example to read in a line, then echo it out
# If you're using Linux, you'll need to use "echo -e"
# instead of "echo"--> UNIX.

echo "Please Enter The Program Name: \c"

# The \c tells echo not to add a new line

read PROG

# That's where it takes your input and stores it into the
# variable "PROG" - you can name this whatever you want

echo "\nThe \$PROG variable was: $PROG"

# The "\n" forces echo to insert a new line at that spot
#Checking processes
ps -ef |grep "$PROG" > f1
cat f1 |cut -c 1-8 > a.1
cat f1 |cut -c10-14 > b.1
paste a.1 b.1 > B
cat f1 |cut -c49-72 > c.1
paste B c.1 > final
echo "STARTING TO CHECK"
echo "3"
sleep 1
echo "2"
sleep 1
echo "1"
cat final |more
rm f1
rm a.1
rm b.1
rm c.1
rm B
rm final

Thanks.
Marcus.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question