cancel
Showing results for 
Search instead for 
Did you mean: 

BEMCLI -WAIT for jobs !!

Mark_Eades
Level 3

I am on that uphill struggle to adsorbe the syntax of powershell and I am having dubious success in trying to enable a -WAIT option for commandlets. With the sample below, on invoking successfully an Invetory, it is TRUE as soon as the job is accepted, not when it is complete which could be after a few minutes.

I need to check for successfull completion of a job before moving to the next nested loop, or not. I thought it would probably be best to look for a "JobSuccess" flag but testing for this in a loop appears far harder than I expected. I am also concious that in scripting an intensive loop can have considerable overheads so would LIKE to put a delay in there, say a second !

Has anyone the knowledge required to help me query BEMCLI for job success or failure ?

function prompt
{
    Write-Host ("BEM " + $(get-date) +">") -nonewline -foregroundcolor White
    return " "
}

$M = import-module "c:\program files\symantec\backup exec\modules\bemcli\bemcli"

If ($M -ne ""){
 echo "Module Imported OK"
 Prompt

 If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEInventoryJob){

 # I need a wait loop here to check the above job has completed but so far cant get a -wait, do until or while.. method to work !


  Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok
  echo "Tape Inventory Completed"

  # If Successfull Next Loop JOB else ...

 # end loop
 }
}
Else {
 echo "Module Not Imported"
}

1 ACCEPTED SOLUTION

Accepted Solutions

pkh
Moderator
Moderator
   VIP    Certified

Use Wait-BEJob to wait for your job to complete.  Your script should look like 

Get-BETapeDriveDevice -Name "TAPE" | Submit-BEInventoryJob | Wait-BEJob | Write-Host 

 
The Write-Host cmdlet is to write the job history to the console.  This will show the sucess/failure of the job.  There is no need for the loop.  If you put your import-module statement in your profile, then this statement is all that is needed.  See my article
 
https://www-secure.symantec.com/connect/articles/preparing-your-powershell-environment-run-bemcli-and-scripts
 
Also, there are a couple of other things that you can do with BEMCLI
 
https://www-secure.symantec.com/connect/articles/using-bemcli-speed-tasks
 
https://www-secure.symantec.com/connect/articles/use-bemcli-chain-jobs

View solution in original post

6 REPLIES 6

pkh
Moderator
Moderator
   VIP    Certified

Use Wait-BEJob to wait for your job to complete.  Your script should look like 

Get-BETapeDriveDevice -Name "TAPE" | Submit-BEInventoryJob | Wait-BEJob | Write-Host 

 
The Write-Host cmdlet is to write the job history to the console.  This will show the sucess/failure of the job.  There is no need for the loop.  If you put your import-module statement in your profile, then this statement is all that is needed.  See my article
 
https://www-secure.symantec.com/connect/articles/preparing-your-powershell-environment-run-bemcli-and-scripts
 
Also, there are a couple of other things that you can do with BEMCLI
 
https://www-secure.symantec.com/connect/articles/using-bemcli-speed-tasks
 
https://www-secure.symantec.com/connect/articles/use-bemcli-chain-jobs

Mark_Eades
Level 3

I prefer to keep all scripts completely self contained rather than rely on the profile having what is needed. Also makes for greater portability on my part as I can use the base scripts anywhere.

smiley

 | Wait-BEJob is exactly what I was looking for in terms of pausing until the job ended. Thank you.

Of course it has now thrown up a miriad of new questions... SORRY !

When I run:

$M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok)
Write-Host $M.name

I get $M = 'Job Success' as required

When loading the modules, 'if I force it to fail' my test logic is wrong as $M simply filled with the error output. Any idea how you would test for a successful import or would you try to filter the output for a key word ?

I noted also, if I type EXIT in the console, it will close, within a script it appears to be ignored. That does require more research !

 

 

BE_KirkFreiheit
Level 4
Employee

You can use Get-Module to test whether a module you've imported is available:


import-module bemcli
if ((get-module bemcli) -ne $null) { $M = (Get-BEAlert -Category "JobSuccess") | Clear-BEAlert -Response Ok}
 
 
The -ne syntax means "not equal", so your code above only gets executed if the bemcli module exists in the powershell session.

One other note: you shouldn't have to type the full path to BEMCLI in your import-module statement.  At install time, the path to the BEMCLI module is added to your environment's PSModulePath variable.  You can test that like this:

c:\> $env:PSModulePath
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Symantec\Backup Exec\Modules

 

pkh
Moderator
Moderator
   VIP    Certified

I am using Server 2003 and I installed Powershell v2.0 after I install BE 2012.  Thus I need the full path of the BEMCLI module.

pkh
Moderator
Moderator
   VIP    Certified

You don't really have to test whether the import-module is successful or not.  If the import-module is not sucessful, all your BEMCLI commands will fail.

Mark_Eades
Level 3

OK after everyone input, the end result is:

function prompt
{
    Write-Host ("BEM " + $(get-date) +">") -nonewline -foregroundcolor White
    return " "
}

#import-module "c:\program files\symantec\backup exec\modules\bemcli\bemcli"
import-module bemcli
if ((get-module bemcli) -ne $null){
 Write-Host "BEM Modules Imported OK"
 Prompt
 Write-Host "Starting Inventory Job"
 If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEInventoryJob|Wait-BEJob){
  $M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
   If ($M.name -eq "Job Success"){
    Write-Host "Inventory:" $M
    Write-Host "Starting Erase Job"
    If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEEraseMediaJob -Confirm:$false|Wait-BEJob){
     $M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
     If ($M.name -eq "Job Success"){
      Write-Host "Quick Erase:" $M
      Write-Host "#run backup code here"
     }
     Else {
     If (Get-BETapeDriveDevice -Name "TAPE" -BackupExecServer "SERVER"|Submit-BEEraseMediaJob -Confirm:$false -LongErase|Wait-BEJob){
      $M = (Get-BEAlert -Category "JobSuccess"|Clear-BEAlert -Response Ok -Confirm:$false)
      If ($M.name -eq "Job Success"){
       Write-Host "Long Erase:" $M
       Write-Host "#run backup code here"
      }
     }
    }
   }
  }
 }
}
Else {
 Write-Host "BEM Modules Not Imported"
}