Execute a UNIX script from DOS prompt.

Hello,

I m trying to execute a UNIX task from windows, I am copying few csv files from UNIX platform to my windows using a bat file like

the txt file is as follows :

open 172.21.13.239
root
root
lcd C:\Documents and Settings\aparna_sharma\Desktop\Trunk_Analysis
cd /opt/Trunk_Analysis/
prompt
mget Final_Call_type26.csv
bye

and bat file is as :
ftp -s:download.txt

however , this bat file executes after i manually execute the script after logging onto the unix system, what i want to add is to execute the script before the command mget Final_Call_type26.csv and the next step is that the xecution shld be interactive i mean the input variables that needs to be given an interactive session b/w UNIX and DOS.....

After searching through this forum and google i heard abt dos2unix and unix2dos.... ssh command ... but i m not clear with there usage and functions.....

Pls suggest with possible answeres....

Thks in advance...........

Aparna

To grab input in a batch file, assuming a modern version of Windows (I believe NT4 and above, but not 100% sure,) you can use SET:

SET /P myvar=Enter prompt here: 

For more information, see SET/? in Windows (Start -> Run -> cmd)

On the other hand, if you just want a shell on the Unix box, do look into shell. Install a client, such as PuTTY. Log in, depending on the client you install, and issue command to your heart's content. For example, if you have a command-line ssh client, you can typically do:

ssh user@hostname

Unless you've done some work to automate logins, you'll be prompted for your password. Once that's provided, you're on the host as if you were sitting at a console, more or less.

Thanks for the information but how i should execute the script ...
like the script
: echo " hello " >> hello.csv

and i make a bat file to fetch hello.csv so i need to execute the script ....
i tried using ssh but its not working..pls suggest

Thks
Aparna

I'm not understanding the issue. What do you mean "ssh is not working"? What have you tried? Did you get an error? How do you know it's not working?

And can you give a full example of what you're trying to do? Where is the script created? Where is it executed? How is it built?

Yes i will explain what i want to do......

there is a script on UNIX platform ....
i want to execute the script from DOS and retrive the output...
like in my first thread i explained that i am able to fetch the output by a batch file in same batch file can i run the script also that's placed on my unix platform....

Pardon me if i m still not clear with the task ....
if not pls reply will give more details

Thks
Aparna

Hi,

Have you thought about or can u use the Microsoft SFU (Services for Unix) then you would not have to worry about the DOS prompt. It contains all the common UNIX utilities, including some shell scripting.

I dont know if you are allowed to have this on your network or not, but if you are the Admin, im sure you can do it as long as its not against your company policy.

Here is the link to both download it and read about it:

http://www.microsoft.com/technet/interopmigration/unix/sfu/default.mspx

I also would like to ask how to execute UNIX command thru batch script??

can someone give me a hint how to make batch script that can execute script on unix??

any ideas??

HI All,

I am also keen to know how to execute UNIX command thru batch script??
Or is it that batch script cannot perform such function at all ?

Can some experts give some advice pls ?
Thanks

Some of the ways to execute Unix scripts via a batch environment (windows) is to use protocols such as Telnet, or SSH, and also a good scripting language that supports these protocols
eg
Using Perl Telnet module

Perl SSH Interface

Python SSH

Python Telnet module

In pure windows batch, not that i know of.

Hi Ghost Dog,

Thanks for the info. But i don;t seem to comprehend these methods and the interface.

Take an example of a csh script named "testing"

#!/bin/csh
echo " hello " >> hello.csv

How would i launch this from my windows using Perl telnet modules? Can you give me some guidance ?

hi
everytime you telnet to your machine, there is a login and password prompt
eg
login:
Password:

then when you logged in, the user prompt according to how its shell profile is configured. For my machine and my user that i use for testing, the prompt is

sun4#

So you can try this (Perl telnet module)

#!/usr/bin/perl
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,
                             Errmode=>'die');
 $telnet->open('your_telnet_server');
 $telnet->waitfor('/login:/'); # change this according to your telnet prompt
 $telnet->print('youraccount');
$telnet->waitfor('/Password:/'); #change this according to your telnet password prompt
$telnet->print('youraccountpassword');
 $telnet->waitfor('/sun4\#/'); #change this to the prompt of the user you are testing
print $telnet->cmd('./testing.sh');  
print $telnet->cmd('echo " hello " >> hello.csv');
$telnet->close();

Hi Ghostdog,

For the prompt, how do i find out how the shell profile is being configured. The OS that i will being telnetting is Solaris and i will be activating csh script inside one of the directory.

And, how do i execute this perl script from my windows ?

you can manually telnet to the solaris server using the user account.
then after its logged in, it will have a prompt. Just have to take note of it and assign it in your perl script. In shell, its commonly called the PS1 variable
check here for details. In Solaris, the user profile is usuall .profile in the home dir. you can set the PS1 variable in its profile.

In windows, with perl installed, just type

c:\somedir> perl yourscript.pl

assuming your perl script "yourscript.pl" is in the c:\>somedir directory

Hi Ghostdog,

The last line after i keyed in my password is below. So do i assign "You have new mail" or "$" ?

You have new mail.
$

Can you recommend me a website to download and install perl ?

Using Perl Telnet module

Perl SSH Interface

Python SSH

Python Telnet module

Do all the methods above need installation ? Because once the script is created, i will have to integrate it into excel macro for public usage. So if the rest do not have the relevant protocols installed, they wouldn't be able to use it. It would be best if windows batch files could do the job.

You can try "$"..

personally, i use
Activestate
but there are other flavors, here . you can have a look.

Perl for windows needs to be installed if you do not already have it.
Once the script is created, you can just run it from command line using the Perl interpreter. I don't know how you are going to include your perl script into excel macro, but you can use OLE with Perl to do excel macros. See here
you got to explore on your own from here on, as I seldom do perl+excel macros..so i have not much advice in this area.

for pure batch, the telnet client in Windows does not have capability for auto login.
guess you would have to download 3rd party command line tools like curl, putty etc that you can include in your batch file.

Hi Ghostdog,

I have problems executing the script after installation. My perl script is named as testing.pl.
Error message is in red below.Can you give me some advice?

C:\Perl>perl testing.pl
'perl' is not recognized as an internal or external command,
operable program or batch file.

have you installed Perl correctly, and which version of Perl? the distribution which you have installed should modify the PATH variable for you.
the perl interpreter is usually in the c:\perl\bin directory. So probably you could try
c:\perl\bin\perl test.pl
Also, you can add the perl interpreter path in your windows by modifying the PATH variable. System->Environment variables->Path

HI Ghostdog,

I have downloaded this ActivePerl-5.6.1.638-MSWin32-x86.zip

I tried you method and it does work. However, there's some compliation error.
Can you give me some guidance on this? I am totally new to perl.

C:\Perl\bin>perl testing.pl
Can't locate Net/Telnet.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib
.) at testing.pl line 2.
BEGIN failed--compilation aborted at testing.pl line 2.

hi
you can download the Telnet modulehere

After that, unzip the module. Check that there is a .ppd file
then from the command line,
type

ppm install <filename>.ppd ## substitute <filename>

Activestate PPM will install the module for you.

Hi Ghostdog,

I don;t see any telnet modules in the website you recommended me. What's the file name ?