HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: PERL help needed
Operating System - HP-UX
1826496
Members
2766
Online
109692
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
01-15-2003 04:03 AM
01-15-2003 04:03 AM
HI,
I have a PERL script below which checks for the existence of filenames having the string "spool" as their prefixes and tokenizes the contents of those "spool" files. Purpose of this script is write the necessary information from the "spool" into a log file to indicate users which have been added/removed from a group by respective owner.
Contents of the "spool" as as follows, separated by colons:
remove:ken_lee:groupA:joe_wong:ken_lee
add:ken_lee:groupA:alice:ken_lee
field 1: action add/remove to indicate a user is to be added or remove from a NIS /var/yp/src/group file
field 2: group owner i.e ken_lee
field 3:name of group i.e groupA
field 4: name of user to be added/removed from NIS master group file i.e alice or joe_wong
field 5: group owner again
The script would need to have the group name, group owner and user to be added/remove and the action field from the "spool" file to be written into a log file. The log file would need to be in the format of:
groupname owner user date action
--------------------------------------
groupA ken_lee alice Jan10 add
Names of the log file should be have the following form:
year-month-groupname
e.g. 2003-Jan-groupA
The date field in the log file would be based on date of the "spool" file obtained by doing a "ls -l spool*".
However in my script, I tried creating a file of the form year-month-groupname to be able to write the groupname, owner, user, date, action into it, and the script produced the error attached in this message.
Could someone kindly tell me how I should fix the error in the attachment?
#!/usr/bin/perl
@spoolList = `ls -l /tmp/spool* |grep -v total`;
foreach $i (@spoolList){
@splitSpoolList = split(/\s+/, $i);
$spoolFile = $splitSpoolList[8];
$day = $splitSpoolList[6];
$time = $splitSpoolList[7];
$month = $splitSpoolList[5];
&processSpoolFileList($spoolFile);
}
sub processSpoolFile{
$fileName = shift(@_);
@spoolFileTokens = split(/:/,`cat $fileName`);
#foreach $k (@spoolFileTokens){
# print "$k \n";
#}
$action = $spoolFileTokens[0];
$owner = $spoolFileTokens[1];
$grpName = $spoolFileTokens[2];
$user = $spoolFileTokens[3];
#for($a=0; $a < @spoolFileTokens; $a++){
# print "\$spoolFileTokens[$a] = $spoolFileTokens[$a]
\n";
#}
&writeToLog($action, $owner, $grpName, $user, $day, $time,
$month);
}
sub writeToLog{
local($action, $owner, $grpName, $user, $day, $time,
$month) = @_;
$year = &getYear;
print "$year \n";
$logFile = $year"-"$month"-"$grpName;
print "\$logFile = $logFile \n";
open(file, ">>/home/$logFile") || die "open $logFile for append \n";
print file "group\t owner\t user\t date\t action \n";
print
file "$grpName\t$owner\t$user\t$date\t$action\n";
close file;
}
sub getYear{
$tmpDate = `date`;
print "$tmpDate \n";
@dateStuff = split(/\s+/,$tmpDate);
$year = $dateStuff[5];
print "\$year = $year \n";
return $year;
}
Also, how do I write the contents of the log file with the headers as specified below? :
groupname owner user date action
--------------------------------------
Could anyone kindly help me out?
Thanks
I have a PERL script below which checks for the existence of filenames having the string "spool" as their prefixes and tokenizes the contents of those "spool" files. Purpose of this script is write the necessary information from the "spool" into a log file to indicate users which have been added/removed from a group by respective owner.
Contents of the "spool" as as follows, separated by colons:
remove:ken_lee:groupA:joe_wong:ken_lee
add:ken_lee:groupA:alice:ken_lee
field 1: action add/remove to indicate a user is to be added or remove from a NIS /var/yp/src/group file
field 2: group owner i.e ken_lee
field 3:name of group i.e groupA
field 4: name of user to be added/removed from NIS master group file i.e alice or joe_wong
field 5: group owner again
The script would need to have the group name, group owner and user to be added/remove and the action field from the "spool" file to be written into a log file. The log file would need to be in the format of:
groupname owner user date action
--------------------------------------
groupA ken_lee alice Jan10 add
Names of the log file should be have the following form:
year-month-groupname
e.g. 2003-Jan-groupA
The date field in the log file would be based on date of the "spool" file obtained by doing a "ls -l spool*".
However in my script, I tried creating a file of the form year-month-groupname to be able to write the groupname, owner, user, date, action into it, and the script produced the error attached in this message.
Could someone kindly tell me how I should fix the error in the attachment?
#!/usr/bin/perl
@spoolList = `ls -l /tmp/spool* |grep -v total`;
foreach $i (@spoolList){
@splitSpoolList = split(/\s+/, $i);
$spoolFile = $splitSpoolList[8];
$day = $splitSpoolList[6];
$time = $splitSpoolList[7];
$month = $splitSpoolList[5];
&processSpoolFileList($spoolFile);
}
sub processSpoolFile{
$fileName = shift(@_);
@spoolFileTokens = split(/:/,`cat $fileName`);
#foreach $k (@spoolFileTokens){
# print "$k \n";
#}
$action = $spoolFileTokens[0];
$owner = $spoolFileTokens[1];
$grpName = $spoolFileTokens[2];
$user = $spoolFileTokens[3];
#for($a=0; $a < @spoolFileTokens; $a++){
# print "\$spoolFileTokens[$a] = $spoolFileTokens[$a]
\n";
#}
&writeToLog($action, $owner, $grpName, $user, $day, $time,
$month);
}
sub writeToLog{
local($action, $owner, $grpName, $user, $day, $time,
$month) = @_;
$year = &getYear;
print "$year \n";
$logFile = $year"-"$month"-"$grpName;
print "\$logFile = $logFile \n";
open(file, ">>/home/$logFile") || die "open $logFile for append \n";
print file "group\t owner\t user\t date\t action \n";
file "$grpName\t$owner\t$user\t$date\t$action\n";
close file;
}
sub getYear{
$tmpDate = `date`;
print "$tmpDate \n";
@dateStuff = split(/\s+/,$tmpDate);
$year = $dateStuff[5];
print "\$year = $year \n";
return $year;
}
Also, how do I write the contents of the log file with the headers as specified below? :
groupname owner user date action
--------------------------------------
Could anyone kindly help me out?
Thanks
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 04:47 AM
01-15-2003 04:47 AM
SolutionLine 41 and line 42 need to be concatenated:
print file "$grpName\t$owner\t$user\t$date\t$action\n";
Line 25, the \n"; needs to be wither appended to the above print statement or commented out
Line 37, change to this:
$logFile = $year."-".$month."-".$grpName;
Periods are string concat operators.
Line 13, the subroutine is called processSpoolFile, but you call it on line 10 as processSpoolFileList. So either change the subroutine name from processSpoolFile to processSpoolFileList, or change line 10 to reflect the name of processSpoolFile.
live free or die
harry
Live Free or Die
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 04:51 AM
01-15-2003 04:51 AM
Re: PERL help needed
I attached the changes, but you need to REPLACE the first line from /opt/perl/bin/perl to your /usr/bin/perl.
have fun
live free or die
harry
Live Free or Die
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 04:58 AM
01-15-2003 04:58 AM
Re: PERL help needed
Hi,
If I seen it right you have the \n on a new line. Don't know if this is messed up by cut and past, but this might be your problem.
If you want answers on Perl questions, please look at the site : http://learn.perl.org/
You can subscribe yourself to a mailinglist, and I can garantuee your problem will be solved in minutes.
# print "\$spoolFileTokens[$a] = $spoolFileTokens[$a]
\n";
Best Regs David
If I seen it right you have the \n on a new line. Don't know if this is messed up by cut and past, but this might be your problem.
If you want answers on Perl questions, please look at the site : http://learn.perl.org/
You can subscribe yourself to a mailinglist, and I can garantuee your problem will be solved in minutes.
# print "\$spoolFileTokens[$a] = $spoolFileTokens[$a]
\n";
Best Regs David
@yourservice
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP