STAF automation framework - perl

I am trying to list a directory on remote machine 10.31.236.56
I am using staf for it .the staf document says the command as
LIST DIRECTORY <Name> [RECURSE] [LONG [DETAILS] | SUMMARY] [TYPE <Types>]
[NAME <Pattern>] [EXT <Pattern>] [CASESENSITIVE | CASEINSENSITIVE]
[SORTBYNAME | SORTBYSIZE | SORTBYMODTIME]
so i am using it as
system("staf 10.31.236.56 FS LIST DIRECTORY c:\\RMT\\Log ");
i get the result but when i try t match particular files like
system("staf 10.31.236.56 FS LIST DIRECTORY c:\\RMT\\Log NAME /latest*.*/");
i dont get any response can some one help me ??

Most likely the shell is interpreting the wildcard before it gets passed on to STAF. I'd recommend putting all of the arguments to STAF in quotes so that the shell wouldn't interfere.
For best results, perhaps avoid using system(string) to launch the command, and instead use either qx{} or system(LIST) so that a subshell isn't called.
Perhaps something like this:
my $cmd = "staf 10.31.236.56 FS LIST DIRECTORY c:\\RMT\\Log NAME /latest*.*/";
system(split ' ', $cmd);
When you pass system a single string, it launches a shell, and passes that string as the command to execute. The shell, then, parses that string (including any wildcards), and runs the command. Since you don't want this to happen (as you don't want "latest*.*" to be parsed by the shell), you can pass system a list, which would tell it to just launch staf directly.

Related

What does "supply values for the following parameters mean in command line?"

So inside of my terminal, I created a text file inside a directory (cat > fnames.txt). My initial goal was to write some data into said file. After creating fnames.txt, the following information showed up after trying to append data to the file using (cat >> fnames.txt):
cmdlet Get-Content at command pipeline position 1
Supply values for the following parameters:
Path[0]:
Image of terminal
Does anyone know the reason of this and what it means?
The command cat is in Powershell an alias to Get-Content. The cmdlet reads information from somewhere. The error message means that Get-Content does not have an idea from where you want it to get data, so it asks you.

How do I invoke a command using a variable in powershell?

I want to invoke the shutdown.exe executable in powershell and it is located on C:\WINDOWS\System32\shutdown.exe.
Since we already got the C:\WINDOWS in the variable $env:windir I want to just use it and concatenate the rest of the path into the command. I was trying this:
PS C:\Users\shina> .\$env:windir\System32\shutdown.exe -s
But I got the following error:
.\$env:windir\System32\shutdown.exe: The term '.\$env:windir\System32\shutdown.exe' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
How can I accomplish this?
You can use:
& $env:windir\System32\shutdown.exe -s
Or
. $env:windir\System32\shutdown.exe -s
(note the space).
& is the call operator. You can read more about it here:
Runs a command, script, or script block. The call operator, also known as the "invocation operator", lets you run commands that are stored in variables and represented by strings or script blocks.
. is the dot sourcing operator. You can read more about it here:
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope, overriding existing ones.
The dot sourcing operator is followed by a space. Use the space to distinguish the dot from the dot (.) symbol that represents the current directory.

Powershell | Cannot create new user

I have a script which will attempt to create a new active directory user.
However when I type the command I get the following error:
http://puu.sh/kHEFP/ab8a5b88c7.png
What am I doing wrong?
Puts single qoutes around the Path value, e.g.
-Path 'OU=Pupils,OU=School,DC=gap,DC=local'
See the docs for more information on the parameter usage:
https://technet.microsoft.com/en-ca/library/ee617253.aspx

mkdir call getting failed in Perl

I am trying to create a directory using Perl. But this call fails.
However when I try to create the same directory structure in shell prompt, it works fine.
Could someone please let me know why I am not able to create the directory in the directory structure?
Example:
$absolutepath = "/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata";
print $absolutepath."\n";
mkdir "$absolutepath" or die $!;
In this example, localdatafs1, Domino, mail\abhy.nsf, and Sent are directories that already exist. I want to create a directory called metadata in the directory structure /localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata using Perl. This mkdir call fails.
If I execute the command
mkdir /localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
in shell prompt, the directory gets created successfully.
Why I am unable to create the directory in Perl using the above path?
Your shell understands a different language than Perl. In your shell, the code
/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
produces the string
/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata
In Perl, the code
"/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata"
produces the string
/localdatafs1/Domino/mail?bhy.nsf/Sent/Metadata
where the ? represents a non-printable control character. The Perl code
"/localdatafs1/Domino/mail\\abhy.nsf/Sent/Metadata"
produces the desired string. Note the escaped "\".
$path = "/localdatafs1/Domino/mail\abhy.nsf/Sent/Metadata"
^--- escape character, turning the path into
$path = "/localdatafs1/Domino/mail".chr(1)."bhy.nsf/Sent/Metadata"

How do I reference variables when executing a shell command in PowerShell?

I'm a newbie to PowerShell. What's wrong with my script below? It's not wanting to emit the value of $config. However, when I wrap that command in double quotes, everything looks okay.
param($config, $logfolder)
# Must run log analysis in chronological order.
ls $logfolder | Sort-Object LastWriteTime | % {
perl D:\Websites\_awstats\wwwroot\cgi-bin\awstats.pl -LogFile="$($_.FullName)" -config=$config update
}
# Execute with - .\regen-logs.ps1 webgenesis "C:\inetpub\logs\LogFiles\W3SVC5"
# Returns for each file - Error: Couldn't open config file "awstats.config.conf" nor "awstats.conf" after searching in path "D:\Websites\_awstats\wwwroot\cgi-bin,/etc/awstats,/usr/local/etc/awstats,/etc,/etc/opt/awstats": No such file or directory
As-is, what gets emitted and executed seems to have "-config=$config" passed as an argument. At least, that's my best guess. I don't know if $_ is working correctly either.
If I put quotes around the perl command like so, I get the command I do want to execute.
ls $logfolder | Sort-Object LastWriteTime | % {
"perl D:\Websites\_awstats\wwwroot\cgi-bin\awstats.pl -LogFile=`"$($_.FullName)`" -config=$config update"
}
# Outputs for each log file something like - perl D:\Websites\_awstats\wwwroot\cgi-bin\awstats.pl -LogFile="C:\inetpub\logs\LogFiles\W3SVC5\u_ex110602.log" -config=webgenesis update
If putting quotes around it produces the correct commandline, one way to execute the contents of a string is with Invoke-Expression (alias iex):
$v = "myexe -myarg1 -myarg2=$someVar"
iex $v
Put double quotes around "-config=$config". Without this, PowerShell will interpret -config=$config as one string argument that just happens to contain a $ sign in it.
I think you need to start your perl command out with & so that PowerShell interprets things as a command and not a string.
& perl D:\Websites\_awstats\wwwroot\cgi-bin\awstats.pl -LogFile=`"$($_.FullName)`" -config=$config update
Also, see: Run a program in a foreach