Checking a file on a remote windows server


 
Thread Tools Search this Thread
Operating Systems Solaris Checking a file on a remote windows server
# 1  
Old 03-18-2009
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
# 2  
Old 03-18-2009
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!
# 3  
Old 03-18-2009
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!
# 4  
Old 03-18-2009
just an update, seems as though

ssh user@windowsbox command works when I use unix commands (which is awesome!) Smilie
# 5  
Old 03-18-2009
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"
# 6  
Old 03-18-2009
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?
# 7  
Old 03-18-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking integrity copied from remote server using UNIX command

I am getting a file (abc.txt) using scp from remote server. scp <connect string> -i $HOME/.ssh/id_dsa rem_id@hostname:/var/prod/abc.txt /var/prod/abc.out Before loading I need to check if the file is indeed same , for that I thought of checking the line count but when I used ssh command it was... (3 Replies)
Discussion started by: lalitpct
3 Replies

2. Shell Programming and Scripting

Do I require remote login access to a windows server to transfer files from a UNIX server

Hi All I need to transfer a file from a UNIX server to a windows server. I saw that it is possible to do this using scp command by looking at the forum listed below: ... (2 Replies)
Discussion started by: vx04
2 Replies

3. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

4. UNIX for Dummies Questions & Answers

Checking files in remote server and decide to copy file or not

Hi there, I have a problem in my script, I need to check whether file exists in remote server or not, if the file exists, then stop copy else copy the file to the server.. my code is something like this while read $server do if ssh $server "cd $directory_name; if ; then echo "Error:... (2 Replies)
Discussion started by: beezy
2 Replies

5. Shell Programming and Scripting

FTP using script not working (for transfering file from a remote unix server to windows PC.)

hi, Im using the following code for FTP #!/usr/bin/ksh ftp -v -n "10.29.45.11" << cmd user "mahesva" "mahesva123" get rtl.tar quit cmd Below is the log when i run the above code ********************************** Connected to 10.29.45.11. 220 (vsFTPd 2.0.1) 530 Please login with USER... (20 Replies)
Discussion started by: dll_fpga
20 Replies

6. Shell Programming and Scripting

Checking the file in remote server using SFTP

Hello, I would appreciate if any one can help me on this. The below script start running at 12:30AM. Every 5 min, i go and check the remote site. If i see filewatch.txt over there, then i need to call another shell script and load the data into database. If i don't see that file, then i have to... (2 Replies)
Discussion started by: govindts
2 Replies

7. Linux

Install Linux on remote server from Windows PC

I am very new with servers and have never used Linux. The server I'm looking at is not currently connected to anything, and I wish to install Linux on this server. It doesn't have a monitor (no video card) or keyboard. It does have a DVD. Can I communicate with that server using a Windows PC to... (8 Replies)
Discussion started by: kvalenti
8 Replies

8. Shell Programming and Scripting

Checking for availability of remote server

Hi. In my KSH script I'm running a command on a remote server. I want to know how I can test to see if the remote server is available (accessible) prior to running the command. Any ideas? My command looks like: `ssh $USER@$TARGET_SERVER_DNS ls -l $REMOTE_FOLDER ` This check should be... (4 Replies)
Discussion started by: dylanmilks
4 Replies

9. IP Networking

Checking for availability of remote server

Hi. In my KSH script I'm running a command on a remote server. I want to know how I can test to see if the remote server is available (accessible) prior to running the command. Any ideas? My command looks like: `ssh $USER@$TARGET_SERVER_DNS ls -l $REMOTE_FOLDER ` This check should be... (1 Reply)
Discussion started by: dylanmilks
1 Replies
Login or Register to Ask a Question