P. 1
Samba

Samba

|Views: 167|Likes:
Publicado porNurul Istiqomah

More info:

Published by: Nurul Istiqomah on Dec 14, 2010
Direitos Autorais:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/21/2014

pdf

text

original

The previousexamples were trivial uses of pseudo printers in that they used only the first
two lines of file. This example uses a longer file,while still retaining the simplicity nec-
essary for an example. To begin,create the following file called scripts/addnames.pl
(note the plural):

#!/usr/bin/perl -w
use strict;
my($filename)=”people/people.txt”;

# GRAB THE EXISTING LIST
open(NAMELIST, “<$filename”);
my(@namelist) =;
close(NAMELIST);

# GRAB THE ADD LIST, BLOW OFF PROGRAM NAME AT TOP
open(PRINTFILE, “<” . $ARGV[0]);
my(@addlist) = ;
close(PRINTFILE);
shift @addlist;

Using Samba Server-Side Automation

CHAPTER14

423

14

U

S
I
N
G

S

A
M
B
A

S

E
R
V
E
R

-
S

I
D
E

A

U
T
O
M
A
T
I
O
N

Note

If these are run with less than a second or so between them, they error out on
an access error of the DOS temporary file temp.tmp. This can be prevented by
placing a delaying command between ssacmdcommands.

17 8628 CH14 3/17/00 1:15 PM Page 423

# MERGE, UPCASE, SORT
push(@namelist, @addlist);
for (@namelist) {tr/[a-z]/[A-Z]/;}
@namelist = sort { $a cmp $b } @namelist;

# DELETE DUPS AND REWRITE NAME LIST
my($prev) = ‘noname’;
my(@out) = grep($_ ne $prev && ($prev = $_), @namelist);
open(NAMELIST, “>$filename”);
print NAMELIST @out;
close(NAMELIST);

Now create the following adds.txtfile on the Windows machine:

addnames.pl
Zelda Zimmerman
Ursula Ullman
Tommy Thompson
Steve Shapiro
Rita Rhodes
Felice Fredericks
George Gilmore

Notice that Zelda Zimmerman is already in people/people.txtfrom a prior example.
The program leaves only one copy of her name because it has a “delete duplicates”
process. Now add the names by copying to the printer share:

$ copy adds.txt \\mainserv\pseudo

The people from the Windows box’s adds.txtfile are now in the UNIX box’s

people/people.txtfile,converted to uppercase and sorted in alphabetical order.

Once again,this example is not ready for prime time. It needs file or record locking,sep-
arate fields for first and last names as well as other information,and a real database to be
useful. However,it does give you an idea how a DOS or Windows process can easily
update UNIX data.

You're Reading a Free Preview

Descarregar
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->