Re: [Networker] How can I do this in perl?
2004-11-10 22:23:43
Here is a perl snippet I use where I write it all out to a file first
and then pipe it to the nsradmin command. I can send you the entire
script if you want it.
Irene Reed
# Now we will make the change to the legato client.
# We will create the input file for the nsradmin -i command
# The following will edit the clients with schedule AIX_NT_Incr (sch1)
open (FSOUT1, ">/tmp/legfs1$$") || die "Could not create the file for
$sch1 with nsradmin | $!";
print FSOUT1 "show save set\n";
print FSOUT1 "print type: NSR client; name: $hsfq; schedule: $sch1\n";
print FSOUT1 "update save set: " . join(", " , @fsnodumps) . "\n";
close (FSOUT1);
open (Q1, "/usr/bin/nsradmin -s $server -i /tmp/legfs1$$ 2>&1|") || die
"Could not run nsradmin | $!";
close (Q1);
unlink ("/tmp/legfs1$$");
# Now we will make the change to the legato client.
# We will create the input file for the nsradmin -i command
# The following will edit the clients with schedule DBDumps_Incr
open (FSOUT2, ">/tmp/legfs2$$") || die "Could not create the file for
$sch2 with nsradmin | $!";
print FSOUT2 "show save set\n";
print FSOUT2 "print type: NSR client; name: $hsfq; schedule: $sch2\n";
print FSOUT2 "update save set: " . join(", " , @fsdumps_sort) . "\n";
close (FSOUT2);
open (Q2, "/usr/bin/nsradmin -s $server -i /tmp/legfs2$$ 2>&1|") || die
"Could not run nsradmin | $!";
close (Q2);
unlink ("/tmp/legfs2$$");
}
-----Original Message-----
From: Legato NetWorker discussion [mailto:NETWORKER AT LISTMAIL.TEMPLE DOT EDU]
On Behalf Of Darren Dunham
Sent: Wednesday, November 10, 2004 5:47 PM
To: NETWORKER AT LISTMAIL.TEMPLE DOT EDU
Subject: Re: [Networker] How can I do this in perl?
> How can I do the equivalent of this shell script in perl?
>
> #!/bin/sh
> /usr/sbin/nsradmin -s server -i <<EOF
> . type: NSR $1; name: $2
> print
> EOF
There are several ways.
#1 most like your shell..
#!/usr/bin/perl
system ("/usr/sbin/nsradmin -s server -i " . <<EOF);
print type: NSR $ARGV[0]; name: $ARGV[1]
EOF
#2
#!/usr/bin/perl
open (ADM, "|/usr/sbin/nsradmin -s server -i") or
die "Couldn't open pipe to nsradmin.\n";
print ADM "type: NSR $ARGV[0]; name: $ARGV[1]\n";
Neither of those solutions capture the output. It just goes to STDOUT
and the screen. Something like...
my @reply = `/usr/sbin/nsradmin -s server -i " . <<EOF`;
print [whatever....]
EOF
would return the data in @reply.
> where I'm just printing out the info to standard output and $1 and $2
> are passed to the script and would be something like 'client' and
> 'client_name', or 'group' and 'group_name', etc. I tried all kinds of
> open commands with pipes, etc. Nothing seems to work.
--
Darren Dunham ddunham AT taos DOT com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
--
Note: To sign off this list, send a "signoff networker" command via
email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
--
Note: To sign off this list, send a "signoff networker" command via email
to listserv AT listmail.temple DOT edu or visit the list's Web site at
http://listmail.temple.edu/archives/networker.html where you can
also view and post messages to the list. Questions regarding this list
should be sent to stan AT temple DOT edu
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
|
|