Reputation: 1047
I really want to use ps -aux
to get this.
So I wrote script:
#!/bin/bash
if [ $# -lt 1 ]; then
echo -n "No arguments were written"
read uid
else
uid=$1
fi
procesy=`ps -aux | awk '{if ($1=="$uid") print$2}'`
echo $procesy
Why it is not working ?
When I am writinig ./script root
I am getting nothing but blank line.
Upvotes: 1
Views: 168
Reputation: 2722
In your script you have a problem using a shell variable inside awk
. The right way using awk
should be something like:
#!/bin/bash
if [ $# -lt 1 ]; then
echo -n "No arguments were written"
read user
else
user=$1
fi
procesy=`ps aux | awk -v usr=$user '{if ($1==usr) print$2}'`
echo $procesy
Upvotes: 1