Page 1 of 2

Unable to view log files on remote server in another domain

Posted: 05 Jan 2014 22:26
by tbharber
Hey All,

I am working on a script to view log files on a remote server in another domain and am running into an issue. Below is what I get when I try to do this...

Code: Select all

runas /user:a083138@proghsz "type \\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin\RuleEngine.txt | find ERROR"

Enter the password for a083138@proghsz:

Attempting to start type \\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin\RuleEngine.txt as user "a083138@proghsz" ...

RUNAS ERROR: Unable to run - type \\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin\RuleEngine.txt
1787: The security database on the server does not have a computer account for this workstation trust relationship.




I am at a loss for how to work around this. I know some built in applications will work just fine. "systeminfo" for example works just fine with no issues...

Code: Select all

systeminfo /u proghsz\a083138 /p xxxxxx /s scnice01



An anyone think of a workaround that will allow me to view the files as shown above?

Re: Unable to view log files on remote server in another dom

Posted: 05 Jan 2014 22:38
by foxidrive
Your path has spaces in it. Test if a txt file can be typed in a folder where there are no spaces.

You may need to use "%comspec% /c type path\filename.txt"

Re: Unable to view log files on remote server in another dom

Posted: 05 Jan 2014 22:54
by tbharber
No luck either way with a text file with no spaces...


Code: Select all

runas /user:a083138@proghsz "type \\scnice01\c$\text.txt"
Enter the password for a083138@proghsz:
Attempting to start type \\scnice01\c$\text.txt as user "a083138@proghsz" ...

RUNAS ERROR: Unable to run - type \\scnice01\c$\text.txt
1787: The security database on the server does not have a computer account for this workstation trust relationship.




runas /user:a083138@proghsz "%comspec% /c type \\scnice01\c$\text.txt"
Enter the password for a083138@proghsz:
Attempting to start C:\Windows\system32\cmd.exe /c type \\scnice01\c$\text.txt as user "a083138@proghsz" ...

RUNAS ERROR: Unable to run - C:\Windows\system32\cmd.exe /c type \\scnice01\c$\text.txt
1787: The security database on the server does not have a computer account for this workstation trust relationship.

Re: Unable to view log files on remote server in another dom

Posted: 05 Jan 2014 22:57
by foxidrive
Try this to see if it is cmd that is the issue.

"%comspec% /c echo abc"

Re: Unable to view log files on remote server in another dom

Posted: 05 Jan 2014 23:02
by tbharber
That works just fine...

Code: Select all

%comspec% /c echo abc
abc

Re: Unable to view log files on remote server in another dom

Posted: 05 Jan 2014 23:51
by foxidrive
I'm out of ideas.

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 02:05
by tbharber
The only workaround I have found so far is to use the "net use" command to map the folder to a drive letter...

Code: Select all

if exist l:\ (net use l: /d  > nul)

net use l: "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin" passwordhere /user:proghsz\a083138 > nul

findstr /L "ERROR" l:\RuleEngine.txt

net use l: /d  > nul



This works but I'm not a fan of how messy it is. I am making the assumption that the users drive letter (L in this case) is free to use and if not the script will not work. I suppose I could make a loop to look for each drive letter that is free but again this is messy and a lot of extra work since all I want to do is look at the contents of a file.

If anyone has any more suggestions I would love to hear them.

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 07:18
by Squashman
I am not at work to test but I am wondering if the TYPE command supports UNC paths.

Other options:

As seen on StackOverFlow
http://stackoverflow.com/questions/3716 ... batch-file

Code: Select all

net use * "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin" passwordhere /user:proghsz\a083138

or

Code: Select all

net use "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin" passwordhere /user:proghsz\a083138


I would have to test when I get to work but the 2nd option may allow you to then use PUSHD to assign the drive letter and change to that paths directory.

Code: Select all

pushd "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin"

This would normally just assign a drive letter and immediately put you into that drive letter.

And this isn't messy at all.

Code: Select all

net use * \\server\share
for /f "tokens=2" %%i in ('net use ^| find "\\server\share"') do set netdrive=%%i
echo %netdrive% has been mapped

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 08:13
by foxidrive
Squashman has nailed this I think.

pushd with a UNC path maps a temporary drive letter that is free, performs the task and the popd unmaps it.

So this should work:

Code: Select all

pushd "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin"
type "RuleEngine.txt" | find ERROR
popd


It may require authentication - I hadn't thought of that.
pushd has no way of supplying credentials

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:05
by Squashman
foxidrive wrote:It may require authentication - I hadn't thought of that.
pushd has no way of supplying credentials

I think if you use the net use with credentials first and then the PUSHD it should work.

Code: Select all

net use "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin"  /user:proghsz\a083138 passwordhere
pushd "\\scnice01\d$\Program Files\NICE Systems\Applications\ServerBin"

According to the stackoverflow post you don't need to specify the driver letter at all and this should get the credentials going.

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:27
by foxidrive
net use requires a * or a drive letter next, AIUI.

If you use * it will assign a free drive letter, and then maybe the pushd will work - that needs to be tested, and I don't have a LAN to check it atm.

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:33
by Squashman
I just tested this and it worked for me.

Code: Select all

H:\>net use "\\Server\E$\BatchFiles" /user:domain\squashman password
The command completed successfully.


H:\>pushd "\\Server\E$\BatchFiles"

Z:\BatchFiles>dir
 Volume in drive Z is Data
 Volume Serial Number is F0A8-D2F3

 Directory of Z:\BatchFiles

12/16/2013  12:34 PM    <DIR>          .
12/16/2013  12:34 PM    <DIR>          ..
08/17/2012  11:36 AM               434 MybatFile.bat

Z:\BatchFiles>type \\server\E$\BatchFiles\Mybatfile.bat
cd \
J:

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:35
by Squashman
You don't even need the PUSHD because TYPE can then use the UNC path.

Code: Select all

Z:\BatchFiles>popd

H:\>type \\Server\E$\BatchFiles\Mybatfile.bat
cd \
J:

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:37
by foxidrive
Good one.

We'll have to see how tbharber goes in his tests.

Re: Unable to view log files on remote server in another dom

Posted: 06 Jan 2014 09:39
by Squashman
Don't forget to delete the mapping.

Code: Select all

H:\>net use "\\server\E$\BatchFiles" /delete
\\server\E$\BatchFiles was deleted successfully.