views:

87

answers:

4

Hi,

i am working on unix. i want to write a shell script which will check for a file called "temp_file.txt" on windows and then execute some commands. is this possible?

how could we connect to the windows and go to a specific directory and check for a file?

A: 

you could set up SSH on Windows and then write a script on Unix using the SSH client to connect to Windows and execute the command. The alternative, if you can afford to, it to write a windows batch, and execute your command on Windows itself. Or you can turn on Windows terminal services, and use telnet protocol from Unix to issue the command. Programming languages that support telnet includes Perl (Net::Telnet) and Python(telnetlib)

ghostdog74
+2  A: 

Share the directory on the Windows machine using the "regular" Windows file sharing facilities. On the Linux side, you have two options:

  1. Use smbclient to connect to the Windows machine and check if the file exists or

  2. Use smbmount to mount the shared directory into your Linux file system and check file existence using "standard" Linux commands (e.g. test).

The exact implementation details will depend on the scripting language that you use, but your pseudo-code will look something like this:

loop:
    check if file exists
    if yes: do something useful
    sleep for some reasonable time

(I am assuming that you want to execute the commands on the Linux machine.)

Heinzi
A: 

As ghostdog74 suggested, ssh is your best bet. You can run something like (I assume you have Cygwin or SFU installed)

ssh "[ -e $file ] && do_something.sh" > do_something.log

If your command logs to stdout, you get the log on your Linux box as well.

If you set up private key authentication, it gets even better.

Dan Andreatta
+1  A: 

If you're using Linux (you specify that you're using Unix, but not what variant), check out the inotify API --- this will allow you to set up event responders for filesystem events (much more efficient than polling).

From a shell script, you can use the inofitywait command --- see http://linux.die.net/man/1/inotifywait for more information.

smokris