Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Below is a perl script I am working on. What I need to know is how I can
write the users file to new file until $user and $passwd is read. Then I
need to skip that record. Then I need to continue writing the users file to
the new users file.
I do not know perl at all. I am having no luck in finding example code that
is doing what I am trying to do.
thanks in advance for you help.
#!/usr/bin/perl
# Perl script to remove a user from the radius users file
# Get user name and password
# search through users file for user name and password
# Open /etc/radiusd-livingston/user
# read user name and password
# Remove user name and user password record from users file
# users record example
# test Password = "password"
# User-Service-Type = Framed-User,
# Framed-Protocol = PPP
#
$file = '/home/optigold/src/Remraduser/user';
# Get user Name and password
print "User Name: ";
$name = <STDIN>; #get users name
chomp $name; #chop off carrige return
print ($name, "\n");
print "password: ";
$passwd = <STDIN>; #get users password
chomp $passwd; #chop off carrige return
print ($passwd,"\n");
#Same as above but turning echo off while password is entered
#print "password: ";
# system("stty -echo"); #Turn off echo to console
# $passwd = <STDIN>;
# chop $passwd;
# print "\n";
# system("stty echo"); #Turn echo back on
# Devine file vars for making backups
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.orig";
# Open files for processing
open(OLD, "< $old") || die "can't open $old: $!";
open(NEW, "> $new") || die "can't open $new: $!";
# This is my print statement from my Addraduser script
# Print new user information to NEW users file
#print (NEW $name," Password = \"",$passwd,"\"","\n",
# " User-Service-Type = Framed-User,","\n",
# " Framed-Protocol = PPP","\n","\n");
# Print OLD user information to the NEW users file until $name and $passwd
reached
# do not print $name, $passwd ,$User-Service-Type and $Framed-Protocol
while (<OLD>) {
(print NEW $_) || die "can't write to $new: $!";
}
# Close out all open files
close(OLD) || die "can't close $old: $!";
close(NEW) || die "can't close $new: $!";
# Make a backup of users file
# copy new users file to users file
rename($old, $bak) || die "can't rename $old to $bak: $!";
rename($new, $old) || die "can't rename $new to $old: $!";
--
To manage your subscription, go to http://mlug.missouri.edu/members/edit.php
Archives are available at http://mlug.missouri.edu/list-archives/