Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup command customization script

Status
Not open for further replies.

vmlavoie

Technical User
Joined
Feb 23, 2005
Messages
3
Location
CA
Hi everybody,

Lately, I have been experimenting with writting customized backup scripts via the `Backup Command`attribute within the client resource.

The environment of the NetWorker server in question is Windows 2000, so I started writing a Batch Dos script but soon realized that this script language is not sophisticated enough for what I wanted to do (Command execution, filtering of arguments, etc...).

So being familiar with UNIX scripting, I installed MKS Toolkit and developed a Korn Shell script that worked fine on the Dos command line. To make it work via NetWorker, I needed a Batch wrapper script to call my Korn Shell script because the nwadmin GUI did not let me enter "sh nsr_save_custom.ksh" in the "Backup Command" attribute in the client ressource. But anyway, it worked. Within the script, I used the "$@" argument on the save command (e.g. save "$@") which put all the input arguments within quotes. So everything was fine until that point. But then I was told that I should not use Korn Shell but Perl...

So, I installed Active Perl and wrote a perl version of my customized save script. It worked fine when I ran it from the Dos command line but did work at all when I tried to call from my Batch wrapper script because the input arguments supplied to the the Perl script were not between quotes... Some arguments (-g) contained spaces.

E.g.
save -s nc1981leg01 -g Test Vincent -LL -m nc1981leg01 -l full -q -W 78 -N c:\toto.txt c:\toto.txt

So my question is: is there an easy way so that the arguments are quoted properly upon entry to the perl script? I know that I can do this in my Perl script but I rather use something functionally equivalent to the "$@" variable that I used within the Korn Shell version of the script.

Any suggestions are welcomed.
 
A few random thoughts:

1) Put the entire desired line into a batch file, e.g. "launch.bat" and have the batch wrapper launch that file instead of the big long command string

2) Experiment putting some of your command line stuff in single or double quotes



 
Also, when trying to figure out what is actually being passed to a Perl script via the command line temporarily use this script (args.pl) instead of your real script:

[tt]for ($i=0;$i<20;$i++) {
print "ARGV[$i] is [$ARGV[$i]]\n";
}
[/tt]
Now, when you run your script you see what gets passed where...
[tt]
$ perl test.pl this is a test "to see how things" really work
ARGV[0] is [this]
ARGV[1] is [is]
ARGV[2] is [a]
ARGV[3] is [test]
ARGV[4] is [to see how things]
ARGV[5] is [really]
ARGV[6] is [work]
ARGV[7] is []
ARGV[8] is []
ARGV[9] is []
ARGV[10] is []
ARGV[11] is []
ARGV[12] is []
ARGV[13] is []
ARGV[14] is []
ARGV[15] is []
ARGV[16] is []
ARGV[17] is []
ARGV[18] is []
ARGV[19] is []
[/tt]
 
So my question is: is there an easy way so that the arguments are quoted properly upon entry to the perl script?

OK, one question: You are trying to launch a Perl script via a "batch job" (i.e. "AT" command from the Dos prompt) on a Win2K box, and you want to pass the entire command string that you gave to that perl script?
 
A "logging version" of the args.pl script (modify output filename as needed):
[tt]open (OUT,">D:\\temp\\args.log");
for ($i=0;$i<20;$i++) {
print OUT "ARGV[$i] is [$ARGV[$i]]\n";
}[/tt]

 
Do not forget that Windows does not support more than 10 variables. You have to use a trick and shift them in a specific way.

Don't know nuch about it (i am not a programmer). But there is an example in the Admin Guide. Please have a look.
 
Hi everybody,

I guess I was not clear enough in the description of my problem. Well, I already did all what was mentionned in the various replies. The problem I have is how the arguments are received by the script called by the batch wrapper script.

If the script called is a Korn Shell type, I use the "$@" variable to pass the save arguments supplied by NetWorker to the save command as follow:

save.exe "$@" > ${Saveout} 2>&1

and if any argument value contains a blank, it is surrounded between quotes (e.g. -g "Test Group") when I use the "$@" argument to pass the variables.

If the script is a Perl Shell, I loose all the quotes and I have to parde myself all arguments in @ARGV and this is what I would like to avoid because it complicates the logic of the script.

So my question really is: is there a way, when using a Perl script, not to loose the quoting that was present when the variables are passed to it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top