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.....
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.
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
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:
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
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();
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
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.
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.
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
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.