Regular Expression Confusion

455 views
Skip to first unread message

Richard Leadbetter

unread,
Dec 17, 2021, 10:53:45 AM12/17/21
to rundeck-discuss
Hi All

1st time post for me, and i am probably missing something really stupid, but does rundeck handle regular expressions differently? I have some output that i want to grab data from and i have built a regular expression to do this. It works when when i plug into test tools like "Regex101" but when i use the "Multiline Regex Data Capture" option, i contiunally get "empty map". 

The Regex i am using is: 
(\d+)(?=\s*bytes free\)$)

I want to run it against this kind of output:
devicename#dir flash:
Directory of bootflash:/
   11  drwx            16384  May 12 2021 04:35:38 +01:00  lost+found
 7713  drwx             4096  May 12 2021 04:35:42 +01:00  .prst_sync
   12  -rw-        467842664  Oct 29 2021 00:32:17 +01:00  universalk9_npe.x.y.z.SPA.bin
23137  drwx           253952  Dec 17 2021 08:24:44 +00:00  tracelogs
38561  drwx             4096  Nov 19 2021 01:07:29 +00:00  .installer
   13  -rw-             1180  May 12 2021 05:23:33 +01:00  FOC2517R03M_2023453542_5434536.lic
30849  drwx             4096  Nov 19 2021 00:57:51 +00:00  core
53985  drwx             4096  May 12 2021 05:30:33 +01:00  .rollback_timer
61697  drwx             4096  May 12 2021 05:39:50 +01:00  .dbpersist
30850  drwx             4096  May 12 2021 05:33:51 +01:00  onep
   15  -rw-             1183  Oct 19 2021 13:09:29 +01:00  FOC2517R03M_1886.2.lic
   16  -rw-             1178  Oct 19 2021 13:09:42 +01:00  FOC2517R03M_1886222.lic
   17  -rw-        467275561  Oct 19 2021 13:11:18 +01:00  universalk9_npe.x.y.z.SPA.bin
61699  drwx             4096  Nov 19 2021 01:11:58 +00:00  license_evlog
1241329664 bytes total (234946560 bytes free)

devicename#


Looking to match the value 234946560. As i say, works fine in regex 101, what am i missing?

I am trying to get this working so i can start making a case for the company to cough up for a licence. 

Any help would be greatly appreciated. 
Thanks
Rich

rac...@rundeck.com

unread,
Dec 17, 2021, 12:46:22 PM12/17/21
to rundeck-discuss

Hi Rich,

Please try with the following regex ^.*\((.*)\s*bytes free\).*$.

^ -> key/value data start.
.* -> anything.
\) -> the parentheses character.
(.*) -> capture anything after the parentheses.
\s*bytes free\).* -> until this pattern (space, “bytes free”, parentheses, anything).

I left a full job definition example:

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 6b2400f4-ae38-4678-aefd-5cb98a66423b
  loglevel: INFO
  name: REGEX
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - fileExtension: .sh
      interpreterArgsQuoted: false
      plugins:
        LogFilter:
        - config:
            invalidKeyPattern: \s|\$|\{|\}|\\
            logData: 'true'
            name: mydata
            regex: ^.*\((.*)\s*bytes free\).*$
          type: key-value-data
      script: |-
        echo "   11  drwx            16384  May 12 2021 04:35:38 +01:00  lost+found"
        echo " 7713  drwx             4096  May 12 2021 04:35:42 +01:00  .prst_sync"
        echo "   12  -rw-        467842664  Oct 29 2021 00:32:17 +01:00  universalk9_npe.x.y.z.SPA.bin"
        echo "23137  drwx           253952  Dec 17 2021 08:24:44 +00:00  tracelogs"
        echo "38561  drwx             4096  Nov 19 2021 01:07:29 +00:00  .installer"
        echo "   13  -rw-             1180  May 12 2021 05:23:33 +01:00  FOC2517R03M_2023453542_5434536.lic"
        echo "30849  drwx             4096  Nov 19 2021 00:57:51 +00:00  core"
        echo "53985  drwx             4096  May 12 2021 05:30:33 +01:00  .rollback_timer"
        echo "61697  drwx             4096  May 12 2021 05:39:50 +01:00  .dbpersist"
        echo "30850  drwx             4096  May 12 2021 05:33:51 +01:00  onep"
        echo "   15  -rw-             1183  Oct 19 2021 13:09:29 +01:00  FOC2517R03M_1886.2.lic"
        echo "   16  -rw-             1178  Oct 19 2021 13:09:42 +01:00  FOC2517R03M_1886222.lic"
        echo "   17  -rw-        467275561  Oct 19 2021 13:11:18 +01:00  universalk9_npe.x.y.z.SPA.bin"
        echo "61699  drwx             4096  Nov 19 2021 01:11:58 +00:00  license_evlog"
        echo "1241329664 bytes total (234946560 bytes free)"
      scriptInterpreter: /bin/bash
    keepgoing: false
    strategy: node-first
  uuid: 6b2400f4-ae38-4678-aefd-5cb98a66423b

Check the final result here.

Hope it helps.

Richard Leadbetter

unread,
Dec 24, 2021, 5:39:27 AM12/24/21
to rundeck-discuss
That worked an Absolute Treat!!!! thank you very much.. I'll use this as an example to build a load more out. 

Can't thank you enough and hopefully i won't be coming back with any more silly questions :)

Merry Christmas / Happy Holidays
:-)

Reply all
Reply to author
Forward
0 new messages