Hi I have created a file temp.txt with the the content as below
root
root123
ls -lrt
exit
and then I am excuting the below command in dos
c:\>telnet machine_ip < temp.txt
Output is
Welcome to the Microsoft Telnet client
Escape character is 'ctrl+]'
C:\> Telnet>
How to automate the telnet session in windows with this method. I cant use any other exe(putty.exe) or tool to do this. I have to use the available things in windows xp. Suggest me also if any other way is there.
I am not sure if you can pass the username and password to telnet program from a text file.
You can create a vbs script and use sendkeys to pass username and password.
Create a batch script which starts a telnet session of a box and then call the vbs script from the batch script using
CSCRIPT //NoLogo //B "C:\Path\to\Script>script.vbs"
Hope this helps!
Related
I have a windows batch file to connect from Server A (Windows) to
Server B (UNIX) via sftp to get a file. The script is as below:
sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg#hostnameB
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
exit
When I run the script it stops after running the first line i.e sftpg3 -oStrictHostKeyChecking=no...
D:\APPBASE\EAPSG\GEMSSG>sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg#hostnameB
Warning: ignoring unsupported option -o
Warning: ignoring unsupported option -o
Remote system type is POSIX.
sftp>
It didn't execute below lines:
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
If I run the command manually one line at a time it works.
Any idea why the script does not run completely?
Thank you.
That's because sftpg3 is a sftp like client which prompt an interactive session with the server waiting for input. so your first line in the script just opens the session and wait until that command (which is the prompt opened) to exit. you need to redirect the input into that prompted session (in unix like using <<) I don't know how it is done in windows. but if the aim from writing that script is to copy a file from the server you can just use scpg3
I am trying to monitor the cmd output of a certain executable .exe and use it for another process running at the same time.
The problem is that all cmd redirecting functions ( '>','>>','<' and '|') would only redirect the output after a successful return of the last command.
What I wanted to do is to generate some kind of streaming log of my cmd.
You can run in your process in background by using
start /b something.exe > somefile.txt
Windows 20H2: Redirection works fine when logged in as true administrator but will NOT work when logged in as a created administrative user. I have used it for years to redirect the output of a multi target backup system using Hobo copy to put the console output in a log file. I have never been able to get it to work successfully in Windows 10 ver 19 or 20 on a created administrative user.
You can prefix the command with "cmd /c" to start a new command prompt, and redirect the output of the command prompt:
cmd /c YOUR CODE > TextFileName.txt
Note : Use ONLY single greater than (>)
Since the output of cmd is going to TextFileName.txt.
Whereas this misses the error output, so you are not able to see : Request to UnKnown timed-out for each failed address.
I am writing a batch command to send data via FTP. Before sending the actual data I need to find if the FTP server is active/running. How do I check that in batch command?
The server responds with "220 server ready" message when it is connected.
Do something like this:
YourFTPCommand | find /i /v "220 server ready" && goto :ServerNotReady
Explanation:
Pipe the output of your FTP command to FIND
Do a case insensitive (/i) search for output that does not contain (/v) the string "220 server ready"
Go to someplace if such a string is found (&&)
I do not think there's a reliable way to do this with Windows ftp.exe.
It blindly keeps running the commands, no matter if connection or previous commands succeeded.
It won't even report the result via exit code.
All you can do is to parse the ftp.exe output.
You should better use a 3rd-party FTP client.
For example with WinSCP scripting you can use:
#echo off
winscp.com /log=ftp.log /command ^
"open ftp://user:password#example.com/" ^
"put c:\local\path\file.txt" ^
"exit"
If connection (the open command) fails, WinSCP won't execute the following commands (the put).
See also Converting Windows FTP script to WinSCP FTP script.
(I'm the author of WinSCP)
i have an application on windows that requires user name and password to start, but i don't want user to enter the user/password, so i created a script to interact with CMD interface to enter the password, using cygwin on windows 8.1, but i can't find expect command on the Cygwin, and i would like to ask also if my script has any issue.
below is the script
#!/usr/bin/expect
sh C:\Users\Osama.Barakat\Desktop\batchfile.bat
expect "Enter the password for administrator:"
send "Pa$$w0rd"
interact
I identified two issues in your question:
How to perform batch files in cygwin/bash?
How to get expect installed/running in cygwin/bash?
1. How to perform batch files in cygwin/bash?
In your sample code, I found
---8<---
sh C:\Users\Osama.Barakat\Desktop\batchfile.bat
--->8---
IMHO, this is a mistake. I believe that bash will try to execute anything as script regardless of the script file extension. But if batchfile.bat is really a batch file then it should be called with the correct interpreter (i.e. cmd.exe) instead.
I tried it to see if there is any issue in the cygwin bash but it worked. My sample batch file test-expect.bat:
#echo off
rem output
echo Hello %USERNAME%
rem input
set /p INPUT= Enter input:
rem output
echo Input: %INPUT%
...tested in bash on cygwin:
$ cmd /c test-expect.bat
Hello Scheff
Enter input: Hello cmd
Input: Hello cmd
$
OK, done.
2. How to get expect installed/running in cygwin/bash?
To install expect on cygwin I googled a little bit and found Installation of Cygwin, expect and Ssh. Then, I started the cygwin-setup setup-x86.exe and tried something else:
On the "Select Packages" page, I set View to Full and Search to expect. I got a list of four entries only where the first was: "expect: Tool for automating interactive applications" (Category: Tcl). I choosed this for installation and had to confirm another package as dependency.
After installation, I tried this in an interactive bash:
$ which expect
/usr/bin/expect
$
OK - looks quite good.
Combining CMD.EXE and expect
To put all together, I wrote another test script test-expect.exp:
#!/usr/bin/expect
spawn cmd /c test-expect.bat
expect "Enter input: "
send "Hello expect\r"
interact
Tested in bash on cygwin:
$ ./test-expect.exp
spawn cmd /c test-expect.bat
Hello Scheff
Enter input: Hello expect
Input: Hello expect
$
Well, it seems to work.
I have to call two bat files.
One name cbpp_job and other upload.bat.
In first .bat files, I have called cbppservice.exe and after that I have call upload.bat.
cbpp_job.bat
call d:\csdb_exe\CBPPService.exe
call ftp -n -s:"d:\csdb\Success\upload.bat" xxxx.produrl.com
upload.bat
user XXXXXX
XXXXXXXXX
PUT ZA1P.FTP.CBPP.INTRFACE.GRP(+1) 'ZA1P.FTP.CBPP.INTRFACE.GRP(+1)'
BYE
EXIT
But when I call csdb_job through command prompt it works well. When I scheduled it in task scheduler it only calls cbppservice.exe and it is not doing the ftp.
The operating System is windows server 2008.
If your event viewer doesn't show you why your script is failing, Try modifying cbpp_job.bat to redirect stderr to a log file.
(
d:\csdb_exe\CBPPService.exe
ftp -n -s:"d:\csdb\Success\upload.bat" xxxx.produrl.com
) 2>"c:\csdbtask.log"
Maybe that'll help you figure out why task scheduler is failing.