I launched putty through PowerShell :

&'C:\test\dev.lnk' is more precisely a link to the dev server opened via putty .

In the open window, I need to write the path to the scripts: cd script .

Is it possible to somehow write this path through powershell , and then run the scripts?

Those. How can I write something using PowerShell in a previously opened window?

  • Do you need a solution on the client side? - aleksandr barakin
  • Yes, I need to make sure that the Powellshell script runs PuTTY to enter the path to the scripts, and then enter the scripts themselves. I do all this manually, but running hundreds of scripts each time is very long. I apologize if I somehow explained wrong. - user184343
  • it may be easier to automate the launch of "hundreds of scripts" on the server side. they just need to be written to the file — one command at a time — and pass the file with the first argument to bash . - aleksandr barakin
  • but on this " monster " did not look? - aleksandr barakin
  • Unfortunately, I am a full humanist, so I hoped that you can do everything just like that. I will try to figure out how to do it through bash or a module, but I’m unlikely to succeed. Thanks for your answers :) - user184343

2 answers 2

To automate the execution of a fixed set of commands in unix-like operating systems, you can do this:

  1. enter all the commands in a file with an arbitrary name (in the file names it is better to avoid spaces and other special characters, limit to lower case letters, Arabic numerals, full stop, minus and underscore) - one command per line:

     команда1 команда2 команда3 
  2. put this file in a directory, for example, /usr/local/bin/ : it is usually listed in the PATH environment variable, so the files placed in it can be run anywhere by their names.
  3. set the executable bit to the file:

     chmod +x /usr/local/bin/moj.nabor.comand.nomer.raz 
  4. Run this file by name:

     moj.nabor.komand.nomer.raz 

reservation

if you do not have permissions to write to the /usr/local/bin/ , place the file in your home directory, and immediately after login, run it like this:

 sh moj.nabor.komand.nomer.raz 

    Alternatively, you can use a bunch of pscp to put the scripts on the server, then plink , to execute the command on the server. But in this case, I don’t really understand the meaning of using PowerShell - it’s quite possible to get along with the banal BATCH script. Both utilities come with PuTTY .

    An example of a PowerShell script using pscp and plink:

     $PuTTYPath = "C:\Program Files (x86)\PuTTY" $User = 'administrator' $Pass = Read-Host 'Password' -AsSecureString | ConvertFrom-SecureString $HostName = 'ubuntu-test' # Кладём скрипт на сервер; обязательно с флагом -Wait, чтобы скрипт дождался загрузки файлов Start-Process -FilePath "$PuTTYPath\pscp.exe" ` -ArgumentList "-pw $Pass D:\Soft\Ubuntu\*.sh $User@$HostName`:/home/administrator" -Wait # Запускаем скрипты (предполагаем, что нам не важен порядок запуска) Start-Process -FilePath "$PuTTYPath\plink.exe" ` -ArgumentList "-ssh -pw $Pass $User@$HostName cd /home/administrator/ && chmod +x *.sh && ./*.sh"