Sponsored Content
Homework and Emergencies Emergency UNIX and Linux Support Script for deleting orphan ids & unknown gecos Post 302728841 by otheus on Thursday 8th of November 2012 02:01:18 PM
Old 11-08-2012
Power

You probably want to do something like this:

First, add a soft link from /bin/false to /usr/bin/nologin

Next, have a list of user-names in a text file, one name per line. Then prepare the following script:
Code:
!/bin/sh
cat your-text-file-of-usernames |
while read uname ; do
   if chsh "$uname" /usr/bin/nologin ; then
     echo Logins blocked to "$uname" 
   else
     echo An error occurred attempting to block login to "$uname"
   fi
done

Now, it's possible that you will have to add the nologin pseudo-shell to the list of shells that are valid. If it fails for every user, then you'll need to figure out how to add it to the list. The AIX manual says:
Quote:
Valid shells are defined in the usw stanza of the /etc/security/login.cfg file.
You can also instead do this, a very AIX-specific method:
Code:
cat your-text-file-of-usernames |
while read uname ; do
   if chuser account_locked=true "$uname" ; then
     echo Account locked for "$uname" 
   else
     echo An error occurred attempting to lock login to "$uname"
   fi
done

Note, I have not tested this as I don't have access to an AIX host.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to kill stranded/orphan process by users.

I have customers on our AIX/UNIX node startup a process that becomes stranded or orphaned and must be killed. I would like to create a script to check for these orphan processes and kill them. I can have cron run this job. The customers process will run and after 24 hours time out leaving an... (4 Replies)
Discussion started by: rjohnson
4 Replies

2. Shell Programming and Scripting

script to update gecos in passwd file

Hello, I need to add information in the gecos of each login in the passwd file. I have expect installed. I thought about using expect to to read a file with the login names and the gecos information and then execute the command passwd with the -f option. The other option would be to read... (1 Reply)
Discussion started by: jyoung
1 Replies

3. Shell Programming and Scripting

deleting rows & columns form a csv file

Hi , I want to delete some rows & columns from file. can someone please help me on this? Regards. (2 Replies)
Discussion started by: code19
2 Replies

4. UNIX for Dummies Questions & Answers

find, mv and create unknown parent & subfolders

I searched the forum rather thoroughly but still could not find the answer. Hopefully the solution is right under my nose. Here what I need to do, move older data to a Archive folder that is 18 months old and older. I would like to use the following command, find departmentx/* -mtime 530... (5 Replies)
Discussion started by: cheeba
5 Replies

5. Shell Programming and Scripting

Finding a flatfile & deleting first line

I have a small script where I want to see if a file exists & then delete the first line from it. I have code to help me find if the file exists, but I am unsure as to how to then take in the answer and remove the first line from the flatfile: This is what I have so far just to output if the... (3 Replies)
Discussion started by: fatalxkiss
3 Replies

6. Shell Programming and Scripting

script to loop all process ids and take pmap

Hi all, I need a script that will loop around all the current processes and take a pmap -x <process id> and output each pmap to a separate file. Would anyone have a quick command to do this? (2 Replies)
Discussion started by: borderblaster
2 Replies

7. Emergency UNIX and Linux Support

Retrieving a list of "orphan" ids

I have a situation where I would like to retrieve a list of ids on AIX 5.3 server, which do not have proper gecos information. The need is to fix all of these ids before it gets flagged as an audit exposure. Can someone please help me with a command/script to retrieve this list? G (3 Replies)
Discussion started by: ggayathri
3 Replies

8. Emergency UNIX and Linux Support

Email ids from gecos

I would like to extract only the email ids from the gecos of each user id. I have to get the email ids of all the users on the server like this. Can someone please assist me with the command/script? (15 Replies)
Discussion started by: ggayathri
15 Replies

9. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

10. UNIX for Beginners Questions & Answers

List of all ids,groups, privilege ids

I wish to pull out a list of all user ids on the system, including the privileged ids, the groups to which they belong to. Sometimes after deleting an id also, its home dir does not get deleted or an entry is left behind in /etc/passwd. Can someone help me with a script to achieve both. (2 Replies)
Discussion started by: ggayathri
2 Replies
uname(2)							System Calls Manual							  uname(2)

NAME
uname - Gets the name of the current system SYNOPSIS
#include <sys/utsname.h> int uname( struct utsname *name); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: uname(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to a utsname structure. DESCRIPTION
The uname() function stores information identifying the current system in the structure pointed to by the name parameter. The uname() function uses the utsname structure, which is defined in the sys/utsname.h file and contains the following members: char sys- name[_SYS_NMLN]; char nodename[_SYS_NMLN]; char release[_SYS_NMLN]; char version[_SYS_NMLN]; char machine[_SYS_NMLN]; The uname() function returns a null-terminated character string naming the current system in the sysname character array. The nodename array contains the name that the system is known by on a communications network. The release and version arrays further identify the sys- tem. The machine array identifies the CPU hardware being used. RETURN VALUES
Upon successful completion, a nonnegative value is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
If the uname() function fails, errno may be set to the following value: [Tru64 UNIX] The name parameter points outside of the process address space. RELATED INFORMATION
Commands: uname(1) Standards: standards(5) delim off uname(2)
All times are GMT -4. The time now is 11:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy