August 15th, 2003, 11:51 AM
red hat shell script
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:"
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.
August 15th, 2003, 12:46 PM
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.
August 15th, 2003, 01:29 PM
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
October 13th, 2003, 12:53 PM
want any automatic logon to a remote telnet machine. try out the expect script.