- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting: Please help
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
Forums
Discussions
Discussions
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
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
06-10-2004 04:41 PM
06-10-2004 04:41 PM
I have a project to implement a SecureID on all of my HP servers. A part of the project is to create a script to replace the shell of certain users on /etc/passwd with file called /opt/ace/sdshell.
For example: I have a file called users as below "
user2
user3
user5
And I have /etc/passwd as below :
user1:*:778:406:user1 123 for testing only:/home/user1:/bin/sh
user2:*:780:406:user2 124 for testing only:/home/user2:/bin/sh
user3:*:781:406:user3 125 for testing only:/home/user3:/bin/sh
user4:*:782:406:user4 126 for testing only:/home/user4:/bin/sh
user5:*:783:406:user5 127 for testing only:/home/user5:/bin/sh
user6:*:784:406:user6 128 for testing only:/home/user6:/bin/sh
So only the shell's of all the users under file users will be replaced with /opt/ace/sdshell. So the result should be as below :
user1:*:778:406:user1 123 for testing only:/home/user1:/bin/sh
user2:*:780:406:user2 124 for testing only:/home/user2:/opt/ace/sdshell
user3:*:781:406:user3 125 for testing only:/home/user3:/opt/ace/sdshell
user4:*:782:406:user4 126 for testing only:/home/user4:/bin/sh
user5:*:783:406:user5 127 for testing only:/home/user5:/opt/ace/sdshell
user6:*:784:406:user6 128 for testing only:/home/user6:/bin/sh
Pls help. High score will be given.
Thanks.
Negara
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 05:13 PM
06-10-2004 05:13 PM
Re: Scripting: Please help
try the following perl script:
open (USERS,"
open (PASSW,"
@words = split (/:/);
$words[6] = "/opt/ace/sdshell\n" if ($user{$words[0]});
print join(":",@words);
}
I'm sure it can be done much shorter, but this works.
Open user list
Remember each user in associative array
Open passwd
Read all
split, based on colon as seperator
replace 7th word (shell) if 1st word is a remembered user
print list joined by colons
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 05:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 05:37 PM
06-10-2004 05:37 PM
Re: Scripting: Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 05:42 PM
06-10-2004 05:42 PM
Re: Scripting: Please help
grep -f users passwd > temp
sed "s/\/bin\/sh/\/opt\/ace\/sdshell/" temp > unsorted
grep -v -f users passwd >> unsorted
sort unsorted > sdshell
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 05:47 PM
06-10-2004 05:47 PM
Re: Scripting: Please help
Thanks alot for your really great help. It looks fine for me now. All those are running well
I prefer to use the shell one instead perl because lack of knowlegde on this.
Thanks.
Negara
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2004 06:19 PM
06-10-2004 06:19 PM
Re: Scripting: Please help
I have attached the shell script which will do your requirement.
You have to specify the userlists in that script to be changed manually.
Modified file will be there as /etc/passwd_mod. Change the permission as like /etc/passwd.
I have tested with your example contents.
Regards,
Muthukumar