Sponsored Content
Full Discussion: How to ask...???
Top Forums UNIX for Advanced & Expert Users How to ask...??? Post 7477 by nemex on Wednesday 26th of September 2001 06:06:46 PM
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..
 
basename(1)						      General Commands Manual						       basename(1)

NAME
basename, dirname - Returns the base file name or directory portion of a path name SYNOPSIS
basename string [suffix] dirname string STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: basename: XCU5.0 dirname: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
A string to be evaluated. This string may be empty. A file name suffix to be deleted if found. This operand applies to the basename com- mand only, and is optional. DESCRIPTION
The basename command reads the string specified on the command line, deletes the portion from the beginning to the last / (slash), and writes the base file name to standard output. If suffix is specified on the command line and suffix appears in string, the string is returned with the suffix removed. The dirname command reads the string specified on the command line, deletes from the last / (slash) to the end of the line, and writes the remaining path name to standard output. [Tru64 UNIX] The basename and dirname commands are generally used inside command substitutions within a shell procedure to specify an out- put file name that is some variation of a specified input file name. For more information, see the csh(1), ksh(1), and sh(1b) or sh(1p) reference pages. The following table demonstrates the processing applied to characters with particular meanings by the basename and dirname commands. ------------------------------ basename dirname string Result Result ------------------------------ / / / // / / /a/b b /a //a//b// b //a <null> err msg err msg a a . "" . /a a / /a/b b /a a/b b a ------------------------------ NOTES
It is not an error if suffix is not a part of string. EXAMPLES
To display the base file name of a shell variable, enter: basename $WORKFILE This displays the base file name of the value assigned to the WORKFILE shell variable. If WORKFILE is set to /u/gabe/program.c, then program.c is displayed. To construct, in a shell script, a file name that is the same as another file name, except for its suffix, enter the following command, using grave accents: OFILE=`basename $1 .c`.o This assigns to OFILE the value of the first positional parameter ($1), but with its suffix changed to $1 is /u/jim/program.c, then OFILE becomes program.o. Because program.o is only a base file name, it identifies a file in the current directory. The grave accents perform command substitution. To construct the name of a file located in the same directory as another, enter the following command, using grave accents: AOUTFILE=`dirname $TEXTFILE`/a.out This sets the AOUTFILE shell variable to the name of an a.out file that is in the same directory as TEXTFILE. If TEXTFILE is /u/fran/prog.c, then the value of dirname $TEXTFILE is /u/fran and AOUTFILE becomes /u/fran/a.out. ENVIRONMENT VARIABLES
The following environment variables affect the execution of basename and dirname: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the inter- nationalization variables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non- empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: csh(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p) Standards: standards(5) basename(1)
All times are GMT -4. The time now is 12:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy