Skip to content

Zabbix Sender and Trapper - Example 2 - Screen

Video Lecture

Zabbix Sender and Trapper - Example 2 - Screen Zabbix Sender and Trapper - Example 2 - Screen

Description

To keep this process running in the background after you close your ssh session, you can run it inside a screen session.

To start screen,

screen

To detach from a running screen session without exiting it an stopping any of its running processes, then type CTRL-A and then CTRL-D.

To reattach to an existing screen session,

screen -r

If there are more than one screen sessions running on the computer, you wil be shown a list of screen ids to attach to. If the screen id was 51234, then you can attach using the command

screen -r 51234

Python Script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import subprocess
import time

while 1:
    cmd = '/opt/vc/bin/vcgencmd measure_temp'

    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()

    tempC = output.split("=")[1].replace("'C", "").strip()
    #print(tempC)

    cmd = 'zabbix_sender -z 127.0.0.1 -s "raspberrypi" -k "pitemp" -o "%s" ' % (tempC)
    print(cmd)

    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    print(output)

    time.sleep(5)

GNU Screen

How to Scroll in GNU Screen

Comments