new guy needs help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting new guy needs help!
# 1  
Old 06-19-2006
new guy needs help!

Spiders am confused, need to get myself a decent book I think but until that time I need to create a script which will run when a user logs in and checks to see if they are already logged in. The script should check all users but not "root"

I figured the quickest way would be to create a temp file when the user logs in and delete it when they logout. The script checks for this file and if it is found the session gets dropped.

We have a AIX 5.2 box if thats anyhelp.

Thanks in advance
# 2  
Old 06-19-2006
I wouldn't do that - users can become locked out for odd reasons.

If you're worried about lots of inactive sessions, maybe try settting the TMOUT variable.
# 3  
Old 06-19-2006
Nah its not inactive sessions thats the problems its our users logging in 7 or 8 times when our licence agreement with our software provider only allows a max of 4 connections per user.
# 4  
Old 06-19-2006
Not sure if this works on AIX, but using procps (http://procps.sf.net) included in a Linux install, I can do this:
Quote:
ps -fC sshd
From there, it's trivial to count the number of sshd processes by user. I would assume that this is not sshd, but you can substitute your process name.
# 5  
Old 06-20-2006
Hi.
Add these lines to the begining of your /etc/profile:
Code:
# Number of sessions allowed per user.
MAX_SESSIONS=2
# You could use a list here instead of a file...
# You should add a case for each shell also...
case $SHELL in
/usr/local/bin/bash)
   USERS=($(cat /etc/users.txt))
   ;;
/usr/bin/ksh)
   set -A USERS $(cat /etc/users.txt)
   ;;
esac
for u in ${USERS[*]}; do
   if [[ $LOGIN = $u ]]; then
      sleep 2
      SESSIONS=$(who -u | grep -i $u | grep -v grep | wc -l)
      if [[ $SESSIONS -gt $MAX_SESSIONS ]]; then
         echo "ERROR:  You have reached your limits ($MAX_SESSIONS sessions)."
         exit 1
      fi
   fi
done

Then create a file named /etc/users.txt
and put there one user per line.
These are the users you want to be limited.

TIPS: - You also should "trap" CTRL+C and so on to be more secure...
- Take into account that this does not control "su" sessions...

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

UNIX Admin rail roaded to be java/jboss guy for development

Any Unix Admins out there who were tasked with upgrading and maintaining java/jboss installs and possibly related apps? How did it work out? Any tools to allow developers to tweak their java settings, like a console? I just started looking into this, if anyone has experience I'd appreciate... (0 Replies)
Discussion started by: allenhibbert
0 Replies

2. UNIX and Linux Applications

New Guy looking for a place to start for UNIX Server and n-tier apps

:o no longer need this. (0 Replies)
Discussion started by: tokposman
0 Replies

3. Shell Programming and Scripting

Can't Commit Directory... is this guy pulling my leg?

Hello, I hired a coder a couple weeks ago to develop 3 small modules for a popular CMS. I created Github repos for each module so as to manage the code and allow others to download it at will. The CMS in question is structured in such a way that each module is housed in its own... (2 Replies)
Discussion started by: fern
2 Replies

4. UNIX for Dummies Questions & Answers

New guy needing help writing a Unix Script

I'm very new with Unix and and am needing assistance in writing a Unix script that will uncompress a dated file then rename it. The script will also need to remove several old files that have a similar naming. The directory that the files reside in is call achdirdep the file that I need uncompress... (1 Reply)
Discussion started by: mlx707
1 Replies

5. UNIX for Advanced & Expert Users

What to teach the new guy

so I have taken on the task of running a few workshops / teaching sessions. we have three new unix people, they have the basics sorted, CD, PWD, LS and such. we are looking at people who have been doing helpdesk untill two months ago. I have given them a few session: file systems, what... (2 Replies)
Discussion started by: robsonde
2 Replies

6. What is on Your Mind?

New guy in the forum

hi everyone. Am just a new guy in this forum interested in advanced shell scripting. I have been running some basic scripts and setting up cronjobs in fedora and its fun, i wanna move to the next level. I got interested in this forum and its gonna take me to the next level. cheers guys, good... (1 Reply)
Discussion started by: dowell
1 Replies
Login or Register to Ask a Question