2 Replies Latest reply on Jun 26, 2014 11:00 AM by Yanick Girouard

    List roles for current user via NSH

    Cody Dean

      Good Morning,

      I am looking for a way to capture the current roles for a user who executes an nsh script, much like the output of chrole.  We have a script that requires users to be logged in as a certain role, and I would like to make it so if they execute the script, it would do a chrole to the correct role first, but to do so, I need to parse their role list.  Thoughts/Ideas/Comments?


      Thank You,

        • 1. Re: List roles for current user via NSH
          Bill Robinson

          This is a script run interactively or as a job ?

          • 2. Re: List roles for current user via NSH
            Yanick Girouard

            Use this code and adapt it to your liking:


            echo_job_info() {
                    USER_NAME=$(blenc -d BLencrypt:"$NSH_USER_NAME" | fields -d : 1 | sed 's/%2c/,/g')
                    ROLE_NAME=$(blenc -d BLencrypt:"$NSH_ROLE_NAME" | fields -d : 1 | sed 's/%2c/,/g')
                    USER_NAME=$(tail -1 <<< "$USER_NAME" | tr -d "\n\r")
                    ROLE_NAME=$(tail -1 <<< "$ROLE_NAME" | tr -d "\n\r")
                    echo_log "Job Name: $1 v$2"
                    echo_log "User Name: $USER_NAME"
                    echo_log "Role Name: $ROLE_NAME"


            It takes the Job name and job version number as parameters, but that was for our own requirements. The part you want is the parsing of the USER_NAME and ROLE_NAME.