- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: PERL scripting problem
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
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
тАО12-01-2002 05:30 PM
тАО12-01-2002 05:30 PM
I have the following PERL script attached in this message. It changes the encrypted passwd field in the /etc/passwd file by reading the newly generated encrypted passwd from another file. Note also that I'm changing passwds not just for HP 11 machines, but also Solaris, AIX and Linux.
This posting is similar in its description on the message which I posted about 1 week ago. At that time, I was looking for a AWK/SED script to solve the problem.
However, I decided to give it a shot with PERL to change the passwd entry in /etc/passwd.
But since I'm a newbie in PERL, my problem now is that I'm not sure how I could write the newly generated passwd into the /etc/passwd file.
I do know how to use PERL's substitution operator to change the passwd with the new passwd, but I do not know how to write those changes in /etc/passwd file.
Could someone help me out with my script attached?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 12:09 AM
тАО12-02-2002 12:09 AM
Solution1. use strict
2. use warnings (for perl 5.005_03 and older use -w)
3. check all your open and close calls
4. use $^O for the OS name instead of unreliable external commands. I don't know the $^O for sunos and linux, so check that yourself)
5. use localtime and time instead of external date command
Tips:
1. use modules when writing cross OS scripts (when portability is an issue in general) instead of external commands
2. keep your lines within 80 characters wide
3. use lexicals wherever possible
4. initialize all your variables
Rewritten script attached
for your core question: unlink might be your clue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 06:42 AM
тАО12-02-2002 06:42 AM
Re: PERL scripting problem
- open passwd for reading
- open a NEW file for writing
- save the old passwd file
- move the old passwd out of the way
- move the new one into place
This way you end up with a backup in case you have some problem (famous last word - "This has gotta work").
I'd especially recommend something like for the passwd file. You'll be scrambling if your code has a bug.
print "Filename";
$name = <>;
$outfile = "newfile";
chomp $name;
open(HANDLE, "<$name");
open(OUTFILE ">$outfile");
while (
{
# do stuff
print OUTFILE;
}
close (HANDLE);
close (OUTFILE);
mv $name $name.save
mv $outfile $name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 07:10 AM
тАО12-02-2002 07:10 AM
Re: PERL scripting problem
Only safety issue you could add is to launch pwck before moving the old one out of the way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 07:27 AM
тАО12-02-2002 07:27 AM