Script to grab all the domain groups for a user on a Linux system with Active Directory connection

#!/bin/sh

clear

USIDTEMP=”/var/tmp/USIDstr.tmp”

GSIDTEMP=”/var/tmp/GSIDstr.tmp”

NAMETEMP=”/var/tmp/NAMEstr.tmp”

#Reseting String storage veribles

>$USIDTEMP

>$GSIDTEMP

>$NAMETEMP

echo “command line to usergroup checker

please supply the domain you wish to check”

read DOM

DOMAIN=$(echo $DOM | tr [a-z] [A-Z])

clear

echo “What username do you wish to list groups for?”

read USERNAME

clear

USERSID=$(WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –name-to-sid=$USERNAME &> $USIDTEMP)

echo “check Remote Proceedure Call (RPC) connection to domain”

echo ” “

WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo -t

echo ” “

echo “———————————————————“

echo ” “

echo “Current Domain Controller Bound To”

echo ” “

WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –dc-info=$DOMAIN

echo ” “

echo “———————————————————“

echo ” “

echo “Check All List Domain In $DOMAIN current Status: “

echo ” “

WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –online-status

echo ” “

echo “———————————————————“

echo ” “

echo ” “

#Save the username sid to a tmp file

WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –name-to-sid=$USERNAME &> $USIDTEMP

#Read in the USID

cat $USIDTEMP | while read LINE

do

USERSID=$(echo $LINE | gawk ‘{print $1}’)

echo ” “

echo “Groups found for $USERNAME are:”

echo ” “

GROUPSID=$(WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –user-sids=$USERSID &> $GSIDTEMP )

cat $GSIDTEMP | while read GLINE

do

>$NAMETEMP

TEST=$(WINBINDD_SOCKET_DIR=/var/samba/$DOMAIN/ wbinfo –sid-to-name=$GLINE &> $NAMETEMP)

cat $NAMETEMP | gawk ‘BEGIN{FS=”\\”}{print $1″,”$2}’ | while read NLINE

do

T=$(echo $NLINE | rev | cut -c1)

if [ $T = 2 ]; then

echo $NLINE | gawk ‘BEGIN{FS=”,”}{print $1″\\”$2}’|sed ‘s/.$//’

fi

done

done

done

Common Linux Commands

#ping google.com

#ping -I ethF 192.168.1.1 (from a particular source interface)

#traceroute google.com

#/sbin/ifconfig (all active network interfaces and some interface statistics)(add or change IP addresses)

# ifconfig -a

# ip addr

#setup (to change the default interface or changing the interface IPs etc)

#reboot

#clear (to clear the screen)

#ip neigh flush all (clear arp cache)

#ifconfig

#dig http://www.google.com (just like nslookup in windows)

#curl http://bbc.co.uk

#route -n (or route (to print the routing table in linux)

#route add default gw 10.0.1.1 eth0 (to add a default route)

#route add -net 10.0.1.0 netmask 255.255.255.0 gw 10.0.1.1

#route del -net 10.0.1.0 netmask 255.255.255.0 gw 10.0.1.1