- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- radius users file - want to script the edit.
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
тАО03-28-2011 07:33 AM
тАО03-28-2011 07:33 AM
0012AB123456 Auth-Type := Local, User-Password == "WIFISECRET"
#Pat Jones Dell Laptop
I was thinking of just concatenating the file but there is header information based on department the guys who built this pig before have headers for departments strung through out the file.
Each Header is Marked with a
# OUR BUSINESS NAME - DEPARTMENT
there are 7 departments
# OUR BUSINESS NAME - Accounting
# OUR BUSINESS NAME - Information Systems
# OUR BUSINESS NAME - etc...
in my script I can find the "Department Section" using
grep "#OUR |grep ${DEPT}"
just not quit sure best way to insert the subcode file i build:
0012AB123456 Auth-Type := Local, User-Password == "WIFISECRET"
#Pat Jones Dell Laptop
any insight or suggestions appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 08:11 AM
тАО03-28-2011 08:11 AM
Re: radius users file - want to script the edit.
You could do:
# cat ./myfilter
#!/usr/bin/perl
use strict;
use warnings;
my $injectionpoint = shift;
my $file_to_inject = shift;
die unless $injectionpoint and $file_to_inject;
open ( my $fh, '<', $file_to_inject )
or die "Can't open '$file_to_inject': $!\n";
my @newtext = <$fh>;
close $fh;
while (<>) {
if ( m{OUR BUSINESS.+$injectionpoint}i ) {
print;
print @newtext;
}
else {
print;
}
}
1;
...where you run as:
# ./myfilter Accounting file_to_insert radius_file
...for example, assuming that you want to add the contents of 'file_to_insert' into the 'radius_file' after the line that begins with "Accounting".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 08:15 AM
тАО03-28-2011 08:15 AM
Re: radius users file - want to script the edit.
But here is one automated way to go about it....
Assume tmp file is called tmp.txt and data file is radius.txt, and department is Acco.
$ awk '/^# OUR/ && /Acco/ {print; while (getline < "tmp.txt" ) {print} $0="" } 1' radius.txt
So we look for a line starting with # OUR COMPANY,
And also having the department name.
If found print that line and,
loop over tmp.txt printing each line and,
clear the last $0 line.
The "1" is always true and makes awk take the default action of printing the current ($0) line.
Use shell quoting, or awk -v option to pass in variables, or just change the line.
fwiw,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 08:17 AM
тАО03-28-2011 08:17 AM
Re: radius users file - want to script the edit.
I think I get the idea, build the insert file first then call the perl routine, to insert into the file.
This definitely will head me in the direction I need to go!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 08:20 AM
тАО03-28-2011 08:20 AM
Solution> I think I get the idea, build the insert file first then call the perl routine, to insert into the file.
Isn't that what you envisioned? If the file to insert always consists of the same text, we could build that too into the script (as a here-document).
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 08:26 AM
тАО03-28-2011 08:26 AM
Re: radius users file - want to script the edit.
$ awk 'BEGIN {RS="~"; getline tmp<"tmp.txt"; RS="\n"} /^# OUR/ && /Acco/ {print; $0=tmp } 1' radius.txt
RS="~"; record seperator = funky character getline new<"tmp.txt"; suck up tmp file into tmp variable
RS="\n"; record separator back to normal new-line
/^# OUR/ && /Acco/ ; right line?
print; right header
$0=new }; set up to print tmp
1; print current line.
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 09:09 AM
тАО03-28-2011 09:09 AM
Re: radius users file - want to script the edit.
Hein, thanks for the info as well. I do have another thing I will post after I get the 1st portion working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 09:42 AM
тАО03-28-2011 09:42 AM
Re: radius users file - want to script the edit.
let me guess....
1)you want the new user after the existing department?
2) sorted?
1)hardcoded
$ awk 'BEGIN {RS="~"; getline new<"tmp.txt"; RS="\n"} END {if (x) print new} /^# OUR/ {if (/Acco/)
{x=1} else { if (x) print new; x=0}} 1' radius.txt
1) with variables
$ awk -vtmp=tmp.txt -vdept=Acco 'BEGIN {RS="~"; getline new
of course by now, as the complexity increases, you want use a full script instead of a 'one-liner' thus far.
[done with my lunch break]
Enjoy,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 09:56 AM
тАО03-28-2011 09:56 AM
Re: radius users file - want to script the edit.
yes, I am planning on building a menu to take the brains out of the picture. as I don't maintain the file, I've got peers who edit files and I wind up chasing mistakes when Radius doesn't restart!.
going to do a Menu that,
Selects the Department, then reads the "username" "Full name" and Password, puts these items in a "tmp file" and then puts this "tmpfile" at an the "insertpoint".
would like to put a check on the username, as we use a "1234567890abcdef" (mac address) to restrict access. (any thoughts on that?)
10 characters required, no more no less, and only typical mac address format.
0012AB123456, or 0021EF654321, etc, etc..
would like to force check, but that is for another day!
Sorting isn't important. the daemon will read the file so long as syntax is as described.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2011 10:27 AM
тАО03-28-2011 10:27 AM
Re: radius users file - want to script the edit.
You can probably do that in the shell.
I would use a regular expression in PERL as in:
$ perl -le '$_ = uc shift; print /^[0-9A-F]{10,}$/'
This prints a 1 if the argument is ok.
Other example:
$ perl -le '$_ = uc shift; print ((/^[0-9A-F]{10,}$/) ? "Good" : "Bad")' 012345678
Bad
the 'uc' upcase function can be dropped if the case is know, or the regexpr is changed to [0-9A-Fa-f]
Hein