Query user
1. Prepare your script
$ mkdir etc bin
$ cd bin
#!/bin/bash
# Tue Aug 4 09:14:09 EDT 2015
# Query Specified user
# Sam Bhusal
# usage sh -xv finduser.sh "john|mary|arya"
# How to use it?
# create two directories bin and etc on your home dir
# on your etc directory create a hosts.ip file with ip and host
# 192.168.10.20 dnsserv1
# 192.168.10.130 appserv1
# Create this file on bin dir
# to use this script
# As a command line parameter, specify the user with | for multiple user
# Usage: yourscript "user1|user2|user3"
#
USERS="$1"
[ $# -eq 0] && { echo ""; echo "Error:- Usage: $0 user_name"; echo ""; exit 1; }
# using for to loop through, you may find better option
for i in `cat ../etc/hosts.ip | grep -v "#" | awk '{print $1}'`
do
echo "Checking $i"
#ssh -q $i /usr/local/bin/sudo cat /etc/shadow | egrep "$USERS"
ssh -q $i cat /etc/passwd | egrep "$USERS"
done
# EOF
--------------------------------
2. Prepare your config file
$ cd etc
$ cat hosts.ip
192.168.10.200 dnsserv1
192.168.10.130 appserv1
# 192.168.10.20 dnsserv1
192.168.10.210 dnsserv2
192.168.10.140 appserv2
3. Now, run your script
$ sh finduser.sh john
or
$ sh finduser.sh "john|mary|sam"
1. Prepare your script
$ mkdir etc bin
$ cd bin
#!/bin/bash
# Tue Aug 4 09:14:09 EDT 2015
# Query Specified user
# Sam Bhusal
# usage sh -xv finduser.sh "john|mary|arya"
# How to use it?
# create two directories bin and etc on your home dir
# on your etc directory create a hosts.ip file with ip and host
# 192.168.10.20 dnsserv1
# 192.168.10.130 appserv1
# Create this file on bin dir
# to use this script
# As a command line parameter, specify the user with | for multiple user
# Usage: yourscript "user1|user2|user3"
#
USERS="$1"
[ $# -eq 0] && { echo ""; echo "Error:- Usage: $0 user_name"; echo ""; exit 1; }
# using for to loop through, you may find better option
for i in `cat ../etc/hosts.ip | grep -v "#" | awk '{print $1}'`
do
echo "Checking $i"
#ssh -q $i /usr/local/bin/sudo cat /etc/shadow | egrep "$USERS"
ssh -q $i cat /etc/passwd | egrep "$USERS"
done
# EOF
--------------------------------
2. Prepare your config file
$ cd etc
$ cat hosts.ip
192.168.10.200 dnsserv1
192.168.10.130 appserv1
# 192.168.10.20 dnsserv1
192.168.10.210 dnsserv2
192.168.10.140 appserv2
3. Now, run your script
$ sh finduser.sh john
or
$ sh finduser.sh "john|mary|sam"
No comments:
Post a Comment