Checking a file on a remote windows server

Hi Everyone!

This is what I need to do...
I am deploying some directories over to a windows server 2000/3 box from my solaris10 box and I need to make sure the directories exist.

The only form of connection I have to work with is SSH
Currently, my script deploys the directories over to the windows box using SCP. After each scp command I want to verify the existing directories on the windows box

I am still new to this and I am having a hard time wrapping my head around this...

when I ssh into the windows box I only have windows commands to work with

Is there another way to do this?

the only way I could think of was to

1) scp the directories
2) scp a batch file which checks for the existance of the directory and output exist or notexist to a txt
3) send the output back to my solaris10 box
4) then use some commands on the solaris box to determine if the txt exist (exit=0) or notexist(exit=1)

I was hoping one of you could enlighten me and throw out some thoughts on how to go about this..

thank you so much

Erin

Not familiar with behaviour of sshd on Windows but one can run a command on a remote host thus:
$ ssh host command

So you might be able to run "dir" on your Windows machine from your Solaris box like this:
$ ssh windowsmachine dir > resultfile 2>&1

and then grep the resultfile for the directory you are looking for and if you are lucky then you may get the string <DIR> (DOS style dir result) on each line that is a directory also!

Thanks for the reply

I just tried:

ssh user@windowsbox dir

but it gives me dir not found

I can ssh user@windowsbox then use the command dir but not using that syntax..

any other ideas?
there must be a way to do this

I can't ssh directly into a specific directory of a host right?

like ssh machinename:/export/home

that doesn't seem to work

Any help would greatly appreciated... I'm going to browse the net some more and play around with this...

Thanks!

just an update, seems as though

ssh user@windowsbox command works when I use unix commands (which is awesome!) :slight_smile:

When you ssh in you will normally be placed into the user's home directory.

Interesting about the Unix commands, you may be able to do:
$ ssh user@windowsbox "cd /export/home && ls -l"

or at least:

$ ssh user@windowsbox "ls -l /export/home"

I'm trying to use the test e command on a file on the windows box

I want to (if possible) to capture the exit status

when I do

ssh user@windowsbox test -e filelocation

then run

echo $? I still get exit status 0 even if the file is not there...

Any ideas?

The $? at the Solaris box end is capturing the successful run of the ssh command.

You could try:
$ ssh user@windowsbox "test -f filelocation; echo $?" > resultfile
and then look in resultfile and for a 0 or non-zero character?

or you could try:
$ ssh user@windowsbox "ls filelocation" > resultfile 2>&1

and the check the contents of resultfile for the "No such file or directory" message, e.g.

if [ -z "`grep "No such file or directory" resultfile`" ]; then
echo "File exists."
else
echo "File does not exist."
fi

Thanks for all the help Tony

when I do the ssh user@box command >> resultfile from unix to unix I get the file

but when I do that same command from unix to windows the file is not created on the windows machine or my local (solaris box)

the command that doesn't give me an output file (just to be more clear)

ssh user@windowsbox test -e filenamelocation >> resultsfile

that resultsfile doesn't show up on my unix box where I'm performing the command or the windows box

is there a way to specify where the output can go? (like explicitly setting the unix host for the results file?)

It should be on the Unix box, could try /tmp/resultfile so you know for definite where it is, note >> will append more lines to resultfile hence better to use > in this situation so you only have the result of the last test run in resultfile.

hrmmm

I don't see any results file... when I do this very command from unix to unix everything works but somewhere between the unix to windows box my output is going missing..

and I forgot to add the last bit to the command (might be able to give someone some insight)

ssh user@windowsbox test -e filenamelocation || echo $? > /tmp/results

Thanks Tony

I'm going to play around with this and see if I can get that output

if anyone knows what I'm doing wrong with that command, I would really appreciate the advice

Thanks
Erin

UPDATE:

the following command works for unix to unix (tested on Solaris10)

(this is a simple way to verify files)

ssh user@hostname test -e file_to_check ; echo $? /tmp/exitstatus

that will give you a 1 or 0 in relation to the file being there or not

Anyways, that does not work with my unix > windows ordeal... I always get 0 exit status

I've tried Tony's other solution regarding ls and using grep for the exit status and that is working for me

If there are any other possible ways I would love to hear it :slight_smile:

Kepepcase:
The speech marks around the command "test -e file_to_check ; echo $?" as in:

# ssh user@hostname "test -e file_to_check ; echo $?" > /tmp/exitstatus

ensures that the commands in the speech marks are run on the remote machine, the:
> /tmp/exitstatus
will therefore do its stuff on your local machine and should create the file on the local machine.