equivalente a tela do Windows powershell

2

Estou usando uma máquina Windows como um servidor ssh. Eu quero executar remotamente algumas tarefas que leva várias horas para terminar. Existe alguma maneira de ter um processo persistente, mesmo após a sessão remota do ssh ser desconectada no Powershell?

    
por joon 10.09.2013 / 00:33

4 respostas

2

Após algumas experiências, agora substituí o ssh pelo PowerShell Remoting.

Especialmente, INICIE UM TRABALHO REMOTO QUE MANTENHA OS RESULTADOS NA seção COMPUTADOR REMOTO do about_Remote_Jobs foi muito útil.

Basicamente, meu fluxo de trabalho atual é

  1. Abra uma nova PSSession
  2. Invoque um comando ( Invoke-Command ) no servidor remoto como um trabalho, com Start-Job

Em seguida, posso desligar-me livremente da sessão e depois voltar a ligar à sessão e obter as saídas do trabalho com Receive-Job .

    
por 31.12.2013 / 07:21
2

Use o parâmetro RunasJob por meio de uma PSSession:

(da Ajuda about_remote_jobs)

START A REMOTE JOB THAT RETURNS THE RESULTS TO THE LOCAL COMPUTER (ASJOB)

To start a background job on a remote computer that returns the command results to the local computer, use the AsJob parameter of a cmdlet such as the Invoke-Command cmdlet.

When you use the AsJob parameter, the job object is actually created on the local computer even though the job runs on the remote computer. When the job is completed, the results are returned to the local computer.

You can use the cmdlets that contain the Job noun (the Job cmdlets) to manage any job created by any cmdlet. Many of the cmdlets that have AsJob parameters do not use Windows PowerShell remoting, so
you can use them even on computers that are not configured for
remoting and that do not meet the requirements for remoting.

STEP 1: INVOKE-COMMAND -ASJOB

The following command uses the AsJob parameter of Invoke-Command to start a background job on the Server01 computer. The job runs a Get-Eventlog command that gets the events in the System log. You can use the JobName parameter to assign a display name to the job.

  invoke-command -computername Server01 -scriptblock {get-eventlog system} -asjob

The results of the command resemble the following sample output.

  SessionId   Name    State      HasMoreData     Location   Command
  ---------   ----    -----      -----------     --------   -------
  1           Job1    Running    True            Server01   get-eventlog system

When the AsJob parameter is used, Invoke-Command returns the same type of job object that Start-Job returns. You can save the job object in a variable, or you can use a Get-Job command to get the job.

Note that the value of the Location property shows that the job ran on the Server01 computer.

STEP 2: GET-JOB

To manage a job started by using the AsJob parameter of the Invoke-Command cmdlet, use the Job cmdlets. Because the job object that represents the remote job is on the local computer, you do not need to run remote commands to manage the job.

To determine whether the job is complete, use a Get-Job command. The following command gets all of the jobs that were started in the current session.

   get-job

Because the remote job was started in the current session, a local Get-Job command gets the job. The State property of the job object shows that the command was completed successfully.

  SessionId   Name   State      HasMoreData     Location   Command
  ---------   ----   -----      -----------     --------   -------
  1           Job1   Completed  True            Server01   get-eventlog system

STEP 3: RECEIVE-JOB

To get the results of the job, use the Receive-Job cmdlet. Because the job results are automatically returned to the computer where the job object resides, you can get the results with a local Receive-Job command.

The following command uses the Receive-Job cmdlet to get the results of the job. It uses the session ID to identify the job. This command saves the job results in the $results variable. You can also redirect the results to a file.

  $results = receive-job -id 1
    
por 11.09.2013 / 03:46
1

O que você está procurando são PSSessions.

Da página about_pssessions no technet ( link )

However, unlike the session that starts automatically, you can control the PSSessions that you create. You can get, create, configure, and remove them, disconnect and reconnect to them, and run multiple commands in the same PSSession. The PSSession remains available until you delete it or it times out.

    
por 11.09.2013 / 03:29
1

Como o OP está usando o ssh para se conectar ao Powershell a partir de uma máquina que não seja Windows, ele não pode usar as sessões do Powershell. Ele estaria correndo como se estivesse conectado à máquina local. O cmdlet Start-Job deve fazer o seguinte:

Start-Job -scriptblock {script or command you wish to run as job}

    
por 11.09.2013 / 15:23