putty from a batch file and a script?

泄露秘密 提交于 2019-12-02 05:49:01

问题


I have a batch file that opens putty just fine. c:\putty.exe root@192.168.12.34 -pw boyhowdy. But to make this work for me I need to understand how to include a script of a command so it will run under the putty tool. Like mount –o remount,rw / . Or is this something I can do with a tool called pscp. I am a nube to these tools and really could use some guideance. I have a bunck of these scripts and would really like to automate them. Thankyou


回答1:


  1. If your goal is to execute shell commands remotely through putty, you should probably look at plink (putty without the gui, in other words an ssh client for windows) and then apply the standard here-doc techniques to plink.

  2. plink is part of the putty collection and is also downloadable from the same page as putty.

  3. If you want to execute a local script you would use

    plink user@host -m local_script.sh

  4. For instance. Assuming you're running on some Windows box (fyi the putty suite also runs on Linux) and want to execute a batch of commands on some remote box you would create a shell script on your local machine (say mount.sh) and run it like this:

    C:\> type mount.sh  
    whoami  
    hostname  
    /usr/sbin/mount -t iso9660 -o ro /dev/cdrom /mnt  
    /usr/sbin/mount | grep mnt  
    C:\> plink remoteuser@remotehost -pw secret -m mount.sh  
    remoteuser  
    remotehost  
    /dev/cdrom on /mnt type iso9660 (ro)
    
  5. Also, it's probably better to copy your public key over so that the password is not coded in some batch file.

  6. Finally, be aware that not all environment variable defined in an interactive shell process will be available in the remote shell process. You might need to 'source' some profile script at the beginning of your script.



来源:https://stackoverflow.com/questions/21804019/putty-from-a-batch-file-and-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!