user attributes not showing when I run the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting user attributes not showing when I run the script
# 1  
Old 11-22-2011
user attributes not showing when I run the script

I am new to linux/unix scripting and working in one company on linux project. I got a script that when it executes should give us the users atributes showing who is retriving data? the script should show us who are the users reriving information. I ran that script as sudo ./test4 but finding
the message. unlocking the password will lead to a password less authentication. please help?

Code:
#!/bin/ksh
#set -x
 
############################################################################################################################################################
PID=$$
directory="/tmp/${PID}"
file=$directory/`uname -n`.txt
mkdir -p "${directory}" 2>/dev/null
cd $directory
 
if [ -e /etc/SuSE-release ] 
then 
OS="SUSE" 
elif [ -e /etc/redhat-release ] 
then 
OS="REDHAT" 
fi
#OS=$(uname -s)
 
 
echo "Server%Login%UID%GID%Gecos%Status%Account_expires_on%Password_changed_on%Minage%Maxage%Password_Length%password_history%roles%Last_Used%Last_PTS%Last_FTP%Last_Console%Last_SU%From-To%Home%Shell%Date" >> $file
last > last.txt
 
 
su_string=" su(pam_unix)"
if [ $OS = REDHAT ]
then
grep $su_string /var/log/messages > su.txt
elif [ $OS = SUSE ]
then
grep $su_string /var/log/messages | grep 'su: (to' | sed 's/)//g' | sed 's/(//g' > su.txt
fi
echo $OS
 
# Exit if it is not a RedHat or SuSE 
if [ $OS = "" ]
then 
exit 
fi
 
for i in `cat /etc/passwd |cut -d: -f1 | uniq`
do
k=$i":"
record=`uname -n`
record=$record"%"$i"%"`grep "^$k" /etc/passwd | cut -d: -f3`"%"`grep "^$k" /etc/passwd | cut -d: -f4`"%"`grep "^$k" /etc/passwd | cut -d: -f5`
g=`passwd -S "$i"`
record=$record"%"`passwd -s "$i" | awk '{print $2}'`
record=$record"%N/A"
record=$record"%"`passwd -s "$i" | awk '{print $3}'`
record=$record"%"`passwd -s "$i" | awk '{print $4}'`
record=$record"%"`passwd -s "$i" | awk '{print $5}'`
record=$record"%N/A"
record=$record"%N/A"
record=$record"%N/A"
record=$record"%"`grep $i last.txt | head -1 | awk '{print $4,$5,$6,$7,$8,$9}'`
record=$record"%"`grep $i last.txt | grep 'pts/' | head -1 | awk '{print $4,$5,$6,$7,$8,$9}'`
record=$record"%"`grep $i last.txt | grep ' ftp ' | head -1 | awk '{print $4,$5,$6,$7,$8,$9}'`
record=$record"%"`grep $i last.txt | grep 'console' | head -1 | awk '{print $4,$5,$6,$7,$8,$9}'`
 
if [ $OS = REDHAT ]
then
record=$record"%"`grep -e -$i su.txt | tail -1 | awk '{print $1" "$2" "$3}'`
record=$record"%"`grep -e -$i su.txt | tail -1 | sed 's/(uid*/ /g' | sed 's/(uid*/ /g' |awk '{print $12"-"$10}'`
elif [ $OS = SUSE ]
then
record=$record"%"`grep -e -$i su.txt | tail -1 | awk '{print $1" "$2" "$3}'`
record=$record"%"`grep -e -$i su.txt | tail -1 | awk '{print $8"-"$7}'`
fi
 
record=$record"%"`grep "^$k" /etc/passwd | cut -d: -f6`
record=$record"%"`grep "^$k" /etc/passwd | cut -d: -f7`
record=$record"%"`date`
echo $record >> $file
done
echo "#EOF - Normal End of File Found" >> "${file}"
 
cat "${file}"
cd /tmp
rm -rf "${PID}"

Smilie

Last edited by vgersh99; 11-22-2011 at 02:41 PM.. Reason: code tags, please!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run a shell script in background without showing in the terminal?

Hi Guys, i am having a script which checks for ip address is pingable or not,when i execute this script in terminal it keeps on showing the pinging status of every ip address and it takes more time when i check for 100 ip address,How to do run a script in background without showing in the terminal... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

2. Shell Programming and Scripting

LDAPSEARCH Return NULL User Attributes

Using ldapsearch to return entries from OID for specific attributes. However, if an attribute is null the field value is not returned. Is there anyway to force ldap to return field names in all cases? LDAP: ldapsearch -T -v -h aaaaa -p 111 -D "cn=orcladmin" -w "xxxx" -L -b... (0 Replies)
Discussion started by: u20sr
0 Replies

3. Shell Programming and Scripting

Su to another user to run script

I have a script ( the name is /tmp/script1) , the content is simple , just copy a file to another directory . Now I would like every user will change to a specific user ( eg. userA ) before run this script so that the script will be run by userA , that mean I want only userA run this script , I... (2 Replies)
Discussion started by: ust3
2 Replies

4. Shell Programming and Scripting

Script working when run manually but not in crontab showing path not found

i have a script running using variable defined in .profile when i run that script manually its working but when i run the same script through cron its giving path not found I had defined path in .profile (3 Replies)
Discussion started by: raj_saini20
3 Replies

5. AIX

User attributes not update in user file

Hi Admins, I am running IAX 5.3 I have created a user with attributes maxage et. The user entry i can see in /etc/security/user file with only one attribute admin=false. how to update the user attributes like maxage etc. Regards Pavan (1 Reply)
Discussion started by: newaix
1 Replies

6. Shell Programming and Scripting

Run SAME SCRIPT as different user

Dear all, i am doing an SVN backup script. Almost done. My problem is : Script should run by user : svn There is a chance to run the script by root itself.. so i coded like following #This script path and name ... (2 Replies)
Discussion started by: linuxadmin
2 Replies

7. AIX

Identify User Attributes

SOS Guys... Is there any way to determine the user attributes, mainly if that userid is set as never expire? I do not have admin rights, and I'm working on AIX 5.3 I've tried : lsuser -f <username> but no luck on that (2 Replies)
Discussion started by: freakygs
2 Replies

8. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

9. Shell Programming and Scripting

not showing restore information while run script

Hello, I have the following script to restore file and grep information. However, once it restore file, it showing a lot useless information and different to check which file have the statement "John price $200". Can I not show any information while running script. It only show..when found the... (1 Reply)
Discussion started by: happyv
1 Replies

10. Shell Programming and Scripting

Run the script from another user

Hello Experts I want to run script from another user in unix . Also the script has been calling from SQL. HOST command helps to call the unix file from sql . But my problem is the unix script has to be run by another user. I tried tht following $ sudo su - user2 -c who... (4 Replies)
Discussion started by: Krishnaramjis
4 Replies
Login or Register to Ask a Question