Ad Widget

Collapse

How to run long running script in background

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irfad
    Junior Member
    • Aug 2017
    • 7

    #1

    How to run long running script in background

    Hi,

    I have a shell script contains (lsof) command defined with userparameter which usually take few minutes to complete on large servers.

    Currently I use at to schedule the script in background and read from an output file.

    I tried to use normal methods like & and nohup but it doesn't work when executed as zabbix item and times out despite it works when executed from bash.

    Could anyone help me if there's a way to run it in background instead of using another tool like at
  • jan.garaj
    Senior Member
    Zabbix Certified Specialist
    • Jan 2010
    • 506

    #2
    system.run[command,<mode>]
    mode: nowait - do not wait for end of execution

    Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
    My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

    Comment

    • irfad
      Junior Member
      • Aug 2017
      • 7

      #3
      Originally posted by jan.garaj
      system.run[command,<mode>]
      mode: nowait - do not wait for end of execution

      https://www.zabbix.com/documentation...s/zabbix_agent
      Thank you for the info. Unfortunately, we have disabled EnableRemoteCommands for security reasons which is required to use system.run

      Comment

      • jan.garaj
        Senior Member
        Zabbix Certified Specialist
        • Jan 2010
        • 506

        #4
        Then make your hand dirty and code it: use your favorite programming/scripting language and create utility which will start required command in the background and it will exit immediately. Then you can use that utility in the userparameter. If the output is not huge, then you can write it into shared memory, just to minimize IOPs.
        Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
        My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

        Comment

        • irfad
          Junior Member
          • Aug 2017
          • 7

          #5
          That's a good idea. I will try to work on this and revert back. Thank you

          Comment

          • _Andrey
            Junior Member
            • Jul 2013
            • 27

            #6
            Originally posted by jan.garaj
            Then make your hand dirty and code it: use your favorite programming/scripting language and create utility which will start required command in the background and it will exit immediately. Then you can use that utility in the userparameter. If the output is not huge, then you can write it into shared memory, just to minimize IOPs.
            Suddenly it doesn't work though. I've made a basic python script that creates fork and exits - work as expected when in shell but when I use it through "zabbix_agent2 -t" it's trying to wait it's child and finally KILLS it upon timeout (why?)... Maybe you have the idea how to achieve behavior that you'd mentioned above? Thanks.

            Comment

            Working...