I'm trying to redirect the output of a service program to a file, which i will later use for processing. Below are the contents of my .service file. I also tried the rsyslog approach but the syslog file (output.txt) is not created.
Description=Traffic_Analyzer
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=cmd
StandardOutput=file:abs_path/output.txt
StandardError=file:abs_path/error.txt
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
rsyslog approach
Description=Traffic_Analyzer
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=cmd
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=traffic_analyzer
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
rsyslog config
if $programname == 'traffic_analyzer' then /abs_path/output.txt
modified .service file
Description=Traffic_Analyzer
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
ExecStart=/home/akash/Traffic-Analyzer/sniffer
StandardOutput=file:/abs_path
StandardError=file:/abs_path
#StandardOutput=syslog
#StandardError=syslog
SyslogIdentifier=traffic_analyzer
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
Please let me know if i'm using it incorrectly.