FirstMan
asked on
userprocesses
I have been tackling this question for sometime and i am getting no success whatsoever. the question is to create a script called 'userprocesses' that allows me to find current users logged on and also display what processes they are currently using.
So far i have used this following code:
$ who -a (which display the usenames currenlt online with options)
$ who -s (to list the names, line and time fields)
but i feel that i am going wrong because i am entering commands and not creating a script.
can u help??
So far i have used this following code:
$ who -a (which display the usenames currenlt online with options)
$ who -s (to list the names, line and time fields)
but i feel that i am going wrong because i am entering commands and not creating a script.
can u help??
Hi,
correction
for user in `who | awk ' {print $1} ' | sort -u`
correction
for user in `who | awk ' {print $1} ' | sort -u`
ASKER
thank you for the script, it works pefectly. one more question, if i wanted to do the script as a bash, how would i go about it??
ASKER
"PLEASE DISCARD THE PREVIOUS MESSAGE"
thank you for the script, it works pefectly. one more question, if i wanted to do the script as a bash, how would i go about it?? and instead of having the login name e.g. adam.adebisi, it has the user's real name e.g. Adam Adebisi ??
thank you for the script, it works pefectly. one more question, if i wanted to do the script as a bash, how would i go about it?? and instead of having the login name e.g. adam.adebisi, it has the user's real name e.g. Adam Adebisi ??
Hi,
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
echo processes run by $user_actual:
echo "----------"
ps -u $user
done
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
echo processes run by $user_actual:
echo "----------"
ps -u $user
done
ASKER
ok r u sure that i can use this in /bin/bash?? but i dont want to use AWK??
Hi,
To make bash script:
- Put the following line at the top of the file (1st line) e.g. call it myscript
#!/usr/bin/bash
- Add the provided script in the file myscript
- Make the script file executable:
chmod +x myscript
to run
./myscript
To make bash script:
- Put the following line at the top of the file (1st line) e.g. call it myscript
#!/usr/bin/bash
- Add the provided script in the file myscript
- Make the script file executable:
chmod +x myscript
to run
./myscript
ASKER
ok i entered the following script:
#!/usr/bin/bash
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
echo processes run by $user_actual:
echo "----------"
ps -u $user
done
is this correct for BASH and not AWK??
#!/usr/bin/bash
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
echo processes run by $user_actual:
echo "----------"
ps -u $user
done
is this correct for BASH and not AWK??
Hi,
The above is a shell script that uses different tools and commands on the system including awk, who sort, ps, etc.
The above is a shell script that uses different tools and commands on the system including awk, who sort, ps, etc.
ASKER
ok then. is there alternative to this bit of script:
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
becuase for my knowledge, this is not suitable for BASH. As BASH carry script with 'echo' in it.
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
becuase for my knowledge, this is not suitable for BASH. As BASH carry script with 'echo' in it.
Hi,
I could not understand what you meant. What alternative you are looking for?
I could not understand what you meant. What alternative you are looking for?
ASKER
Ok
i understand that they are different ways to write a script. This script
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
is an awk command which is used for manipulating data and generating reports. I DON'T want to write the script in AWK formant, i want to use BASH command or shell scripting
i understand that they are different ways to write a script. This script
for user in `who | awk ' {print $1}' | sort -u`
do
user_actual=`grep -w $user /etc/passwd | awk -F":" ' { print $5 } '`
is an awk command which is used for manipulating data and generating reports. I DON'T want to write the script in AWK formant, i want to use BASH command or shell scripting
ASKER
This is an example of what i mean
#!/bin/bash
echo "what is your age"
read myVar
echo "Hello $USER you are $myVar years old"
#!/bin/bash
echo "what is your age"
read myVar
echo "Hello $USER you are $myVar years old"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this script
for user in `who | awk ' {print $1} | sort -u`
do
echo processes run by $user:
echo "----------"
ps -u $user
done