Results 1 to 4 of 4

Thread: red hat shell script

  1. #1

    Question red hat shell script

    Hi all,
    hoping you can help. i am working on writing just basic shell scripts for an extra credit class assignment. two questions:

    1. i can add expressions with the following command...prod=`expr 5 + 6`, but can't figure out the symbol for multiplication. the * character will not work for me.

    2. i also am looking to write a small script that takes in a user name and outputs the # of processes being run by that person. not each individual process, just the total number. here is what i have so far:

    echo "Please input a user name to see their total # of processes:"
    read name

    then i am trying to use the "ps -ef" command to display the currently running processes, the variable $name for whatever was typed in by the user, and a counter using grep or we -l. if i'm confusing please ask whatever questions you like. thank you in advance for your assistance.
    A+, Network+ Certified.

  2. #2
    Senior Member
    Join Date
    Mar 2003
    What, do you want someone to give you the points?

    However, I can tell you a couple of things. One, the * will not work for multiplication is shell scritpting because it is used to represent a wild card, like 1*.doc would represent all of the files that begin with the number 1 and have a doc extension. Try /*.

    On your second question, I would try a different command, such as cut. Just like you have, store the user name as a variable and use it as one of your arguments in the command. That should be enough to get you there.

    If you need more, check this out. It is a pretty good reference for shell scripting noobs.

  3. #3
    Senior Member
    Join Date
    Jun 2003
    Hi there,

    You can do the following:-

    1. For calculating expressions use bc. For ex.
    a=$(expr $b+$c | bc)

    2. For the second one you can use grep

    PS -A | grep -c $USERNAME
    will return the count with lines containing $USERNAME

    Hope that helps

  4. #4
    Junior Member
    Join Date
    Oct 2003
    want any automatic logon to a remote telnet machine. try out the expect script.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts