DX Unified Infrastructure Management

 View Only

Expand all | Collapse all

Using logmon 4.20 to mkdir or cat or ls?

  • 1.  Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 03, 2022 01:11 PM
    hi,
    I am wondering if it is possible to use logmon to create a folder , just a basic mkdir foldername

    I have tried using "command" and a wild card match watcher, with a "match expression" variable but mkdir , cat and ls do not return anything and the directory is not created.

    When I change the command to pwd I receive the expected output.

    Is there a limitation or restriction on logmon for doing this.

    -----
    The bigger picture is.
    I want to create symlinks to monitor multiple log files from different locations within the one "custom" dir by running this command as a logmon profile

    mkdir custom/ && ln -sf /u01/app/oracle/diag/rdbms/databasename/alert_log.log /opt/nimsoft/probes/database/oracle/custom/.

    But the first hurdle is failing .. I can't even get an outpur from ls or a cat or a basic txt file


  • 2.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 03, 2022 06:05 PM
    It would be good to see examples of what you are doing but with regards to the question, logmon in the command mode will run the command then scrape the output to match against the watchers. There are no restrictions. Granted you need to know how the command is implemented - there's no "dir" executable in Windows for instance, it's a sub command of cmd.exe so you can't just run the command "dir".  

    Set the log level to 5 and watch the logmon.log output to see what's going on.

    Also, I typically find that it's better to have logmon run a script file, even if it's just a single command, because that way I don't have to worry about how logmon handled the special characters.

    And finally, if you are running a one line command that uses pipes or some other stream processing, I find it helps to put your command within ( ) so that a second sub shell is started to run the actual command.


  • 3.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 04:46 AM
    Edited by Nick Barlow Nov 04, 2022 04:56 AM
    Hi Garin,

    Thanks for the input.
    The is on a Linux OS

    Part of the reason for wanting to avoid running from a shell script is to make it more scalable/easier to tweak after deployment.
    For the intended purpose of creating a symlink, each oracle system will have a different path to file so will need to modded on a file by file basis. It's easier to edit the gui than mod the archive delivered package each time

    The check is very basic:

    Standard command check:

    Wildcard watcher for testing:

    Default var name used with Match Expression:

    The only command that returns anything is pwd , even ls returns nothing .. it would be easier to diagnose if it didn't work at all



  • 4.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 06:52 AM
    OK. I managed to resolve this, well workaround it.
    It looks to be a pathing issue .. I was using ls but /usr/bin/ls is required

    My next challenge is to get logmon to execute a command with a space in it

    /usr/bin/cat test.txt also gives a 127 which I'm sure is cause by the space


  • 5.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 08:08 AM
    You specify the command "/usr/bin/cat test.txt" but test.txt may not be in the current directory of where logmon executes the command. You will want to get in the habit of using full paths so that you eliminate ambiguity.

    Otherwise logmon should have no difficulty at all with this command.



  • 6.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 08:06 AM
    With regard to the script comment, you just need to include the script file in the archive package that you have this logmon config in. That way anywhere you put the config, the script also goes. 

    And logmon has no issue with spaces in the command. It just takes the whole entry and submits it to the shell to execute.

    Regarding your screen shots, a couple comments:

    Suggest that you stick with the regex patterns in the watchers. So your first pattern should be /.*/ and not just * to match everything.

    In a subsequent screenshot you create a variable and you indicate that it should be match expression 1 but in your pattern there are no match expressions defined. You could change the variable to be a character position based and specify character 1 through end of line. Or you could change your pattern to /^(.*)$/ - the parentheses specify the match expression.





  • 7.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 08:16 AM
    I managed to work it out. I'm going to admit a noob error again ............ I was creating the symlink in oracle instead of logmon dir bah :|

    The only challenge I have now is.
    The && seems to cause issues, so I need to work out if there is a switch for ln (LN) that forces directory creation to overcome this:

    [root logmon]# /usr/bin/ln -sf /u01/app/oracle/diag/rdbms/DB/DB/trace/alert_DB.log /opt/nimsoft/probes/system/logmon/custom/.
    /usr/bin/ln: failed to create symbolic link '/opt/nimsoft/probes/system/logmon/custom/.': No such file or directory
    [root1 logmon]#


  • 8.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 10:39 AM
    So, not to repeat the suggestion but if you put the commands in a script file and then use logmon to call the script file you don't have to fret over what logmon might do to any "special" characters it finds in the command.

    I think your ln command is incorrect too. If you are using "mkdir custom/ && ln -sf /u01/app/oracle/diag/rdbms/databasename/alert_log.log /opt/nimsoft/probes/database/oracle/custom/." still, you are telling ln to create a link called "." in the custom directory. Linux is not going to allow that because "." is special and means this directory.

    When logmon runs it will generally (not always but most of the time) execute your commands relative to the location of the logmon executable - probably /opt/nimsoft/probes/system/logmon in your case on Linux.

    But the path on the name of the link to create is /opt/nimsoft/probes/database/oracle/custom which will not have the "custom" directory in it since the command you provided logmon is going to create it in the logmon directory, not the oracle directory.

    what you probably what is something more like:

    mkdir /opt/nimsoft/probes/system/logmon/custom && ln -sf /u01/app/oracle/diag/rdbms/databasename/alert_log.log /opt/nimsoft/probes/system/logmon/custom/alert_log.log

    Granted the mkdir is going to fail on the second execution because it will already exist.

    And not to take this into left field, but it might be useful to understand why you are going through this effort. I suspect that there's a different answer available.

     



  • 9.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 10:47 AM
    It was failing as I didnt path ln fully :)
    Looking good now

    Thanks for the help and input, Garin


  • 10.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 10:58 AM
    I think the final touch would be to run
    /usr/bin/mkdir /$NIM_ROOT/probes/system/logmon/custom/

    That fails, do you happen to have any idea what that would be ? $NIM_ROOT fails


  • 11.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 11:30 AM
    Solved. It succeeds when the probe runs /usr/bin/mkdir /$NIM_ROOT etc :)


  • 12.  RE: Using logmon 4.20 to mkdir or cat or ls?

    Posted Nov 04, 2022 05:00 AM
    Edited by Nick Barlow Nov 04, 2022 06:54 AM
    Log file not required