批处理文件到telnet并在unix服务器上运行命令 [英] Batch file to telnet and run commands on a unix server

查看:133
本文介绍了批处理文件到telnet并在unix服务器上运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在这里,我真的可以帮助您.这是我的情况.

I'm stuck here, and I really can use your help. Here's my situation.

我期待创建一个批处理脚本,该脚本可以使用telnet访问Unix服务器.在此,Unix服务器将要求输入用户名/密码.在对用户进行身份验证之后,我想对垂直文件执行诸如chown的一些操作.

Im looking forward to create a batch script which can access a unix server using telnet. Here the unix sever will ask for username/password. After it has authenticated the user, i want to preform some operations like chown on a perticular file.

这就是我要做的事情:

    telnet
    open xyz.abc.com
    username
    password

    command 1
    command 2
    command 3
    exit 

其中

xyz.abc.com is the unix server where i want to connect.
username and password are the credentials to access this server 
command 1,command 2,command 3 are the commands i want to run in the server.

我的问题是我不能使用SSH. 它应该从文件中获取所有数据,而不是提示用户输入数据,并且应作为自动脚本运行.

My problem is i cant use SSH. It should take all the data from the file instead of prompting the user to enter data and should run as an automated script.

推荐答案

这是我创建的.bat文件,用于通过telnet到服务器,更改文件许可权,然后将该文件ftp到我的PC上并打开它.希望它将对您有所帮助.因为我总是登录并每次都移到相同的目录名称,所以这里有可变的文件名.您可以将其更改为提示,以便用户可以输入他们想要cd的位置.如果您有任何疑问,请告诉我.

This is the .bat file I created to telnet to a server, change a file permission, then ftp the file to my PC and open it. Hopefully it will help you out. The variable filename is there because I always login and move to the same directory name every time. You can change it to a prompt so the user can enter where they would like to cd to. Let me know if you have any questions.

:: This will telnet to the server, change the permissions, 
:: download the file, and then open it from your PC. 

:: Add your username, password, servername, and file path to the file.
:: I have not tested the server name with an IP address.

:: Note - telnetcmd.dat and ftpcmd.dat are temp files used to hold commands

@echo off
SET username=
SET password=
SET servername=
SET filepath=

set /p id="Enter the file name: " %=%

echo user %username%> telnetcmd.dat
echo %password%>> telnetcmd.dat
echo cd %filepath%>> telnetcmd.dat
echo SITE chmod 777 %id%>> telnetcmd.dat
echo exit>> telnetcmd.dat
telnet %servername% < telnetcmd.dat


echo user %username%> ftpcmd.dat
echo %password%>> ftpcmd.dat
echo cd %filepath%>> ftpcmd.dat
echo get %id%>> ftpcmd.dat
echo quit>> ftpcmd.dat

ftp -n -s:ftpcmd.dat %servername%

SET mypath=%~dp0
%mypath%%id%

del ftpcmd.dat
del telnetcmd.dat

这篇关于批处理文件到telnet并在unix服务器上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆