HPE SimpliVity
1830085 Members
13605 Online
109998 Solutions
New Discussion

Automate dsv-balance-show

 
Ibehere
Visitor

Automate dsv-balance-show

Hello,

I've scripted the dsv-balance-show command to email me the results.  The issue I'm having is that when i use a cronjob to run the script it does not work.

Is there anything about the dsv-balance-show command that wont run in a cronjob?

This is the line that effectively does nothing:

source /var/tmp/build/bin/appsetup;dsv-balance-show >> /data/drivespace.txt

Runs fine if I manually execute the script and the rest of the script executes fine as well in the cronjob.

Thanks,

Ernst.

7 REPLIES 7
Mahesh202
HPE Pro

Re: Automate dsv-balance-show

Hi Ernst
Hope you are doing well.!!

Most likely a permissions issue. dsv commands require sudo/root level permissions.
may I request you to try with sudo/root level permissions.

Hope this helps.!!

Regards
Mahesh.



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Ibehere
Visitor

Re: Automate dsv-balance-show

Hi Mahesh,

 

I thought as much so I've tried not only in the users cron job but also root's. /etc/crontab

The script runs and creates the output file but does not contain the drive space data.

Thanks,

Ernst.

Ibehere
Visitor

Re: Automate dsv-balance-show

So not sure if this helps at all...

I added loging and this is what I get:

Error:(47), Caller:48 /etc/drivespace.sh, Command:dsv-balance-show >> /kens/drivespace.txt

Not sure what error 47 means as it looks up as 'Level 3 reset'

Thanks,

Ernst.

gustenar
HPE Pro

Re: Automate dsv-balance-show

The sequence of commands should be:

sudo su

source /var/tmp/build/bin/appsetup

dsv-balance-show

 

Is this how you are executing it?



I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
Ibehere
Visitor

Re: Automate dsv-balance-show

Hi Gustenar,

So I'm running the script as root so the sudo su shouldnt be needed.

The rest is correct.

I have since moved on and completed the task a diferen .  I'm now running the automation via powershell instead of from the linux machine.

I now have the output needed.

Thanks,

Ernst.

Paul747
Occasional Visitor

Re: Automate dsv-balance-show

Hi Ibehere

Your PowerShell solution sounds interesting, coul;d you share an example of your script please

Paul747

 

Ibehere
Visitor

Re: Automate dsv-balance-show

Hi Paul,

Of course...  so the workflow is 2 parts.  A Bash script on the appliance and powershell script on the windows box.  The powershell script has 3 requirements.

An installation of Putty, Posh-SSH module installed, and a set of cached creds for use on the appliance. (not best practice)

Appologies as I'm not the best scripter but this works for me.  

All thats left is to execute the function on a schedule and email out the pulled data file.

Here's the Bash script:

#!/bin/bash

# Script to create drive space file output

# Source Data
. /var/tmp/build/bin/appsetup

# Clean up old file if needed
rm /data/drivespace.txt

# Define Log file location
LOGPATH="/var/log/"
LOGFILE="drivespace.log"
LOGTAG="Drive Space Script"

function error_trap {
	echo "Something went wrong!"
	write_log "Error" "Error:$1, Caller:$(caller), Command:${BASH_COMMAND})"
}

function write_log {
    if [ ! -d "$LOGPATH" ];
    then
        mkdir $LOGPATH
    fi
    
    d=`date +%m_%d_%Y`
    t=`date +%T`
    
    echo [$d] [$t] "$1: " $2 >> $LOGPATH$LOGFILE
}

# Set error trap function
trap 'error_trap $?' ERR 

# Set up Logging...
write_log "Info" "------------------------------------------------"
write_log "Info" "Script Invoked as User: $User" 
write_log "Info" "Script Tag: $LOGTAG"

# Check for Kens Directory
DIR=/data

if [ ! -d "$DIR" ];
then
    mkdir /data
fi

# Write drive space info to file
dsv-balance-show >> /data/drivespace.txt

write_log "Info" "Writting drive space info to file."

 

Here's the Powershell function:

Function Get-OVCDriveSpace
{
  [CmdletBinding()]
  param
  (
    $Hosts,
    [string]$Outfile,
    [System.Management.Automation.PSCredential]$Creds
  )

  # Check output folder
  if (!(Test-Path -Path 'C:\Temp' -PathType Container))
  {
    [Void](New-Item -ItemType Directory -Path 'C:\Temp' -Force)
  }

  Set-Content -Path $Outfile -Value ''

  foreach ($HostItem in $Hosts)
  {
    $SessionID = New-SSHSession -ComputerName $HostItem.IP -Credential $Creds -AcceptKey -ConnectionTimeout 20
    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "SSH Session created to host: $($Hostitem.IP)."

    $null = Invoke-SSHCommand -SessionId $SessionID.SessionId -Command 'sudo /etc/drivespace.sh'
    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "Remote command executed on host: 'sudo /etc/drivespace.sh'."

    $null = pscp.exe -scp -pw $Creds.GetNetworkCredential().Password -l $Creds.UserName "$($HostItem.IP):/data/drivespace.txt" "/Temp/$($HostItem.Name).txt"
    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "Remove file retrieved from host: 'Drivespace.txt'."
    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "Local file saved from host: '$($Hostitem.Name).txt'."
    
    $null = Remove-SSHSession -SessionId $SessionID.SessionId
    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "SSH Session Closed."

    $HostItem.Name | Add-Content $Outfile
    Get-Content -Path "C:\Temp\$($HostItem.Name).txt" | Add-Content $Outfile
    "`r`n" | Add-Content $Outfile

    Write-Log -LogFolderPath $LogPath -LogFilePrefix $ScriptName -Message "File content added to '$Outfile'."

  }
}

 

Thanks,