Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescan log on bash's redirect to new file #144

Open
dfredell opened this issue Mar 13, 2019 · 2 comments
Open

Rescan log on bash's redirect to new file #144

dfredell opened this issue Mar 13, 2019 · 2 comments

Comments

@dfredell
Copy link

Hello,

I currently have a batch job that runs every minute and the stdout is redirected to a new file. We have scalyr-agent installed and if I were to use bash's >> to append to the log file, scalyr-agent works fine.
I wanted to use >, that way I don't have to worry about log rotation, scalyr-agent would have 60 seconds to detect that the file changed and send it to scalyr. Another fun option would be able to pipe my bash output right into the running scalyr, ex
* * * * * update-app.sh | /usr/local/scalyr-agent-2/bin/scalyr-agent-2

Is there a setting or a new feature that would allow the scalyr-agent to detect a file replace?

From scalyr-agent-2 -v status

  /var/cron/logs/auto_update.log: copied 135 bytes (1 lines), 0 bytes pending, last checked Wed Mar 13 15:44:39 2019 UTC

From data/checkpoints.json

    "/var/cron/logs/auto_update.log": {
      "pending_files": [
        {
          "inode": 164152,
          "is_log_file": true,
          "last_known_size": 136,
          "position_end": 0,
          "position_start": -136
        }
      ],
      "position": 0,
      "sequence_id": "6680055e-bcc9-430a-9270-a1134d2444eb",
      "sequence_number": 521
    },

crontab -l

* * * * * update-app.sh > /var/cron/logs/auto_update.log 2>&1

/var/cron/logs/auto_update.log

2019-03-13T16:08:00Z Nothing to update running version 57
@jmorascalyr
Copy link
Contributor

Hello Dan,

Thanks for reaching out.
I am looking into this for you. I'll send an update when I get more info.

Thanks,

Joel Mora

@jmorascalyr
Copy link
Contributor

jmorascalyr commented Mar 19, 2019

Hello Dan,

Thanks for reaching out! From a high level, it seems as if you are looking for a way to run this cron job, write the output to a file, and not have to manage the rotation of the file.

The agent doesn't directly support rotating logs, and there is no setting to make the agent handle the IO Redirection option ">", but there are two solutions I can think of:

  1. As one of our engineers @johnpadilla pointed out, you can try this.
    rm /var/cron/logs/auto_update.log; update-app.sh >> /var/cron/logs/auto_update.log 2>&1

  2. Use the API in your shell script to post the logline. This would allow you to send the log directly to your Scalyr account, bypassing the file altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants