- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: simple script to change the login shell for ma...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 04:16 AM
тАО07-08-2009 04:16 AM
simple script to change the login shell for many users.
There are 400 userids in my HPUX BOX.I want to create a script to change the user's shell to /usr/bin/false.Please give me an outline or scripting details to do this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 04:28 AM
тАО07-08-2009 04:28 AM
Re: simple script to change the login shell for many users.
List the uid's of the users you want changed in a simple file; one uid per line. Then run:
# cat .modusers
set -u
umask 022
typeset INFILE=$1
while read UID X
do
usermod -u ${UID} -s /usr/bin/false
done < ${INFILE}
exit 0
...run as:
# ./modusers ./uidlist
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 05:05 AM
тАО07-08-2009 05:05 AM
Re: simple script to change the login shell for many users.
usermod is probably the right way to go; but, just to show there are always 18 ways to skin a cat in UNIX:
cat ${list-o-users) | while read user
do
echo ${user}
eval "perl -i -ple 's/^(${user}:.*):.*/\1:\/usr\/bin\/false/g' /etc/passwd"
done
The risk on this one is you're playing with the password file directly. If you ensure you have a backup of it (RCS anyone?), verify it's contents afterward, and verify your ability to connect to the server afterward, it's not a major issue.
I did something similar to this when making sweeping gecos field format changes... Got to love meaningless corporate standards...
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 05:59 AM
тАО07-08-2009 05:59 AM
Re: simple script to change the login shell for many users.
do
echo ${user}
eval "perl -i -ple 's/^(${user}:.*):.*/\1:\/usr\/bin\/false/g' /etc/passwd"
done
"
...which appears to also set root's shell to /usr/bin/false which would be a *bad thing*....
one has to wonder why you want to have 400 accounts that can't log in tho....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 06:11 AM
тАО07-08-2009 06:11 AM
Re: simple script to change the login shell for many users.
That would be incorrect - or, rather, correct only if root is in the file referenced as "cat ${list-o-users)". The eval'ed perl statement looks for a line that begins with "${user}:"
If your ${list-o-users} contains:
cipriano
basnyat
rdaihl
mnevin
basisnar
it will look first for a line that starts with "^cipriano:", followed by the next, etc.
Of course, if the user were silly enough to put root in the file, then, yes, it would lock root. That would be why you would want to back up the password file originally, evalute the contents afterward, and verify connectivity afterward...
Doug O'Leary
------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 06:14 AM
тАО07-08-2009 06:14 AM
Re: simple script to change the login shell for many users.
> OldSchool: ...which appears to also set root's shell to /usr/bin/false which would be a *bad thing*....
That would be a very bad thing [ :-) ] if the 'list-o-users' file had 'root' as one of its lines. If it doesn't then Doug's script is one way.
> OldSchool: one has to wonder why you want to have 400 accounts that can't log in tho....
Some of use mused about that in an offline exchange. It could be that Vee needs/wants to keep a historical record of inactivated users to be able to map 'uid's to names (GECOS information?) and/or leave those user's files intact. Of course it would be interesting to know the OP's reason and not our supposition :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 06:15 AM
тАО07-08-2009 06:15 AM
Re: simple script to change the login shell for many users.
I would make a list of users to change, with vi or script.
cat /etc/passwd | awk -F: '{print $1}' > list
...
edit the list unless its all of them.
while read -r name
do
usermod -u ${name} -s /usr/bin/false
done < list
This could be done even more slickly with pipes
------------
cat /etc/passwd | awk -F: '{print $1}'|while read -r uname
usermod -u ${uname} -s /usr/bin/false
done
Maybe /etc/passwd is a different file that contains a subset of users you need to change.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 07:05 AM
тАО07-08-2009 07:05 AM
Re: simple script to change the login shell for many users.
You can also use for loop like this.
Have all the users list in a file called /tmp/users.txt
for USER in `cat /tmp/users.txt`
do
usermod -s /usr/bin/false $USER
echo "user shell modified for the user $USER"
done
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 07:11 AM
тАО07-08-2009 07:11 AM
Re: simple script to change the login shell for many users.
Does anyone ever read the suggestions already posted before posting the same variation?!?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2009 07:24 AM
тАО07-08-2009 07:24 AM
Re: simple script to change the login shell for many users.
in that case, I usually just lock the acct and leave and not mess w/ the shell....but as somebody noted..."many ways to skin a cat"