putty from a batch file and a script?

后端 未结 1 1728
有刺的猬
有刺的猬 2021-01-22 07:58

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 com

相关标签:
1条回答
  • 2021-01-22 08:46
    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.

    0 讨论(0)
提交回复
热议问题