Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi
i have a question for using searching in /etc/shadow with wildcard.it just struct to my mind but i cudnt get hold of it.if any of the linux gurus can help me out.help will be duly appreciated.my /etc/shadow file is
vscan:!:12775:0:99999:7:::
man:*:8902:0:10000::::
man:!:12775:0:99999:7:::
man:!:12775:0:99999:7:::
news:*:8902:0:10000::::
news:!:12775:0:99999:7:::
news:!:12775:0:99999:7:::
man:*:8902:0:10000::::
man:!:12775:0:99999:7:::
man:!:12775:0:99999:7:::
baz:$2a$05QeMyohjS9cDVtYwKTU7LacuaJ7ySc2oDQRBnxCWhrHMbceYZ9urZci:12795:0:99999:7:::
abhishek:$2asaasajajsasajsjansjnajnaj:12323:0:2323:2:::
abhi:@32323232323232:12902:14:93:7:30::now i want to search using wildcards.So if i take user input as ab* it should give me abhishek and abhi .
now i hav used this.for WHO in `$AWK -F":" '{print $1}' $SHADOW` ; do
if [ "$WHO" = "$var" ] ; then
echo "usr found"
else
echo "usr not found"
fi
donecan anyone help me out.i mean how do i search with wildcard * .they seems to be having unpredicatble behaviour
hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no

Hi,
I dont quite get the idea of searching a userid in /etc/shadow as a normal user you wont have access on this file. Also if you just want to check the username why not use /etc/passwd??
Anyway have a look at the following script, may hold the key to your problem.
#!/bin/bash
for WHO in `awk -F":" '{print $1}' /etc/passwd | grep "^$1"`
do
echo $WHO
doneprint only the user id's from /etc/passwd and use grep to do wild card search with $1 passed from command line as parameter to the script. I put it as grep "^$1" meaning beginging of the word.
Hope this helps.

#!/bin/ksh
if [ $# -eq 0 ] ; then
echo "USAGE $0 pattern"
exit 4
fi
PATTERN=$1
for who in `awk -F: '{ print $1 }' /etc/shadow` ; do
if [ `echo $who | grep -c --regex="$PATTERN"` -gt 0 ] ; then
echo "User $who found"
fi
done

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |