putty from a batch file and a script?

£可爱£侵袭症+ 提交于 2019-12-02 01:18:10
  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.

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