Pergunta

So I was doing a development project for my work and basically the idea is that we have a Excel VBA macro that needs to do some parsing of files, create a new file and send the file location to a Unix script running on the mainframe.

The location of the file is different every time you run the macro and thanks to Samba, I can create the file in Windows and it is immediately accessible to the Unix system.

Now the problem arises: how can I pass in the location of the file. The issue is a program called plink (which is a version of putty that allows configuration file to sit alongside the program itself rather than in the registry of PC) is the only approved option to do this work (I know Cgywin would do this quite easily) and the program sits on a network drive with multiple people would probably need to run it concurrently. The authorized_keys file has a exec to point to the Unix script that needs to run and for security reasons, I can not change that. However I can write a script in Unix to take the unnamed parameter and use it to run the script that only takes the parameter (file location) as a named parameter (--file=/directory/datafile).

I tried to run that script with (in cmd) plink.exe serverIP /directory/datafile (the login is already configured) but apparently the parameter could not get passed in this way.

I have also tried plink.exe serverIP "/directory/datafile" and there is no luck there as well.

I am just wondering if there is a short and neat way to get this done. We had a sample project with the similar configuration but the script to do this took like 10000 lines which I don't want to read, I sort of believes this should be done in like a short script with 10 or 20 lines. I am free to create whatever Windows script if I need to, provided that I could run multiple sessions of the program with different parameters concurrently.

Foi útil?

Solução

You should be able to run commands on the Unix machine using plink, just as you would run one unix command on another unix machine using ssh. For example

plink user@host "ls"

Will run ls on host

Likewise:

plink user@host "/absolute/path/to/script/on/unix/machine/script.sh"

Should run script.sh on host. You can build the command that you want to run on the unix machine locally (including any arguments to the script, like path names to data files), then run the command using plink, as above.

If script.sh has parameters, and they're not getting read in, try putting both the script name and the parameters in single quotes:

plink user@host "'/absolute/path/to/script/on/unix/machine/script.sh arg1 arg2'"

You may want to look into the plink documentation, which can be found here: http://the.earth.li/~sgtatham/putty/0.62/puttydoc.txt

Look in particular at section 7.2.2 - 'Using Plink for automated connections'

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top