Automic Workload Automation

 View Only

 How to get username or password values from LOGIN object in a scripting way

Sabine Arthur's profile image
Sabine Arthur posted Aug 01, 2023 12:24 PM

Hello,

I cannot find in de automic documentation the way to get a value from a login object . 

For example, il would like to store in a login object the password of an external ftp , because if i store it on a VARA , it will be readable by everybody which i don't want.

Then, i would like to get the password and use it in a command line in a SCRI or a JOBS.

How can i do this ?

Best regards

Andrzej Golaszewski's profile image
Andrzej Golaszewski

Hello,

what are you searching for ist GET_LOGIN function. I have not tested it with SCRI objects, but for JOBS (Windows,Linux) it is working as described.

Don't forget at first to define your own LOGIN Type.

Stefan Lerch's profile image
Broadcom Partner Stefan Lerch

and a little example to start from:

#!/bin/sh

:SET &PASS# = GET_LOGIN(LOGIN.KREPROD.INFORMIX, informix, APP, PASSWORD)

pass=$(&UC_JOBMD CMD="echo &PASS#")

###pass=$( /opt/automic/agent/bin/ucxj???m CMD="echo &PASS#" )
###pass=$( /opt/automic/agent/bin/ucxjlx6m 'CMD=echo &PASS#' )

You can see it was made for bash; works almost the same way for any other scripting language.

Using &UC_JOBMD is pretty helpful, else you have to hardcode the (path to ) the messenger.

A common problem is quoting. If you see strange things, check single/double quotes backwards/forwards...

Sabine Arthur's profile image
Sabine Arthur

Thank you everyone for you advices .

Did you ever use it in a windows JOBS using powershell interpreter (with :BEGIN_EXT_INT POWERSHELL ) ?

It seems to have some trouble to decrypt the password with this  case . 

This is my code :

:BEGIN_EXT_INT POWERSHELL
:SET &User# = GET_LOGIN(LOGIN.TEST, FTP, Custom-FTP, LOGIN_INFO)
:SET &PASS# = GET_LOGIN(LOGIN.TEST, FTP, Custom-FTP, PASSWORD)
:p &User#
:p &PASS#
&UC_JOBMD CMD="Write-Output= &PASS#"
:END_EXT_INT POWERSHELL
Richard Beck's profile image
Richard Beck

Sabine, for you windows job.

I put this part in my pre-process. 

:SET &User# = GET_LOGIN(LOGIN.TEST, FTP, Custom-FTP, LOGIN_INFO)
:SET &PASS# = GET_LOGIN(LOGIN.TEST, FTP, Custom-FTP, PASSWORD)
and this in my process

:BEGIN_EXT_INT POWERSHELL
$user = "&USER#"

#this uses an encrypted password from the pre-process and decrypts for the credential use below
$pwd = $(&UC_JOBMD CMD="echo  &PWD# ")
$pwd = $pwd.replace("`n","").replace("`r","").trim()

the replace and trim was to get rid of some \n\r characters that crept into the process when I did it within powershell. I'm not sure if that necessary anymore

Eventually I created a windows job and made a vara.exec  to retrieve the decrypted password.

Jared Kessans's profile image
Jared Kessans

I have tested this out in the past and it seemed to work though we are not currently using it.

:SET &LI# = GET_LOGIN(LOGIN.WINDOWS.SERVICEID,'*', ENCRYPTED_PASS,LOGIN_INFO)
:SET &PW# = GET_LOGIN(LOGIN.WINDOWS.SERVICEID,'*', ENCRYPTED_PASS,PASSWORD)
@ECHO OFF
FOR /F "usebackq tokens=* delims=@" %%i IN (`CALL &UC_JOBMD ^"CMD^=echo &PW#^" 2^>nul`) DO SET pw=%%i
:BEGIN_EXT_INTERPRETER powershell
$Login = "&LI#"
$password = $env:pw
$SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force

I should mention that in the forums this solution was provided.

Sabine Arthur's profile image
Sabine Arthur

Big Thank you everyone ! I have my answer(s) .

Michele Adamski's profile image
Michele Adamski

I'm struggling with this. No matter what I do, it returns 

PASSWORD IS 0000000000020482
Richard Beck's profile image
Richard Beck

maybe make it simpler if you can and not deal with *

:set &EPWD#=get_login('&login_object#',"&user_name#",'&type#','PASSWORD')

remember TYPE has to be a user defined system name.  You can't use the agent type.  You have enter a custom one in 

Michael Dolinek's profile image
Broadcom Employee Michael Dolinek

Hi Michele Adamski 

as you can see at https://docs.automic.com/documentation/webhelp/english/AA/24.2/DOCU/24.2/Automic%20Automation%20Guides/Content/Script/Reference/GET_LOGIN.htm the return-code 20482 can be read as "The specified name could not be found in the Login object.". 
Looks like you have a typo in your command.

Michael