3

I'm using Rundeck to run remote jobs through the SSH executor. Some of the jobs I run log to specific files on the host, rather than STDOUT, and I don't have the ability to change this.

Is there any way to tell Rundeck to read those files as they get written (using something like tail -f), and treat what appears there as the job output?

Adding tail -f itself as a step wouldn't work, since it will never terminate.

If need be, a 'hacky' solution will do (like adding extra job steps for copying and reading logs) but ideally I'd like it to be neater. So if you could give me some guidelines how to build a plugin that will take the filename as a parameter and read the output from there, that would be better.

limos
  • 1,526
  • 12
  • 13
  • Why don't you use cat or tail -n or head , where n is the number of lines you wanted to print in stdout.. The above are used to terminate unless the tail -f – Leo Prince Jan 10 '17 at 04:24
  • The problem is I don't know how many lines it will output. I want it to run e.g. /usr/bin/myscript, pipe anything that gets added to /var/log/myscript.out to STDOUT, and stop once /usr/bin/myscript finishes – limos Jan 11 '17 at 10:24
  • Check my answer below.. thats a for loop. It will print as much as line your file have.. Might help you – Leo Prince Jan 11 '17 at 10:25

1 Answers1

1

If you just want a file to read and print on STDOUT, then just use this inline script as additional step in workflow.

#!/usr/bin/python
import os,sys
file_name=sys.argv[1]
if os.path.isfile(file_name):
    with open(file_name) as file:
        for line in file:
            print line
else:
    print 'file doesnt exists'

Give file name as argument

Leo Prince
  • 2,019
  • 26
  • 29
  • Could just cat it in that case. My problem is that I only want the lines that are added to the file, not the whole file – limos Jan 12 '17 at 11:48
  • Take the number of lines first before adding using word count and then append the lines.. check the word count again and find the difference.. tail -n the file where n is the difference of lines before and after the log write.. – Leo Prince Jan 12 '17 at 12:47
  • 1
    Yup, that's more or less what I ended up doing. I'd have liked to have the STDOUT output interspersed with the log file output, at the time it happened, but I can live with this. Thanks for the ideas – limos Jan 15 '17 at 10:20
  • 1
    I want to do the same thing. With this solution rundeck won't show in real time the output. I would like to see in rundeck the output of a log file as soon as it has new entries generated by the main script – RuBiCK Jul 26 '17 at 10:53
  • @RuBiCK May be you can try the solutions told above. Check the file's word count once in a while with either a infinite loop having a sleep that determines the frequency of check. I hope it will work with rundeck but not sure how rundeck gonna handle the live STDOUT. give it a shot – Leo Prince Jul 26 '17 at 11:23