-
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.
-
What, do you want someone to give you the points? :p
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.
-
Hi there,
You can do the following:-
1. For calculating expressions use bc. For ex.
a=0
b=1
c=2
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 :D
-
want any automatic logon to a remote telnet machine. try out the expect script.