I have demon process ex. sample. I have service file which will trigger main process launch file. When system boots up based on this file it will create /var/log/sample.out
and /var/log/sample.err
file for logging.
I need to redirect printf log into this sample.out
file.
Is there way I can do this?
I added below statement to do the same but its not showing any logs in /var/log/sample.out
or /var/log/sample.err
.
${binary} > ${logs}.out 2> ${logs}.err
sample.c
#include<stdio.h>
int main()
{
printf("Demon starteed \n");
}
sample.service
[Unit]
Description="sample service"
[Service]
ExecStart=/usr/bin/sample.service.start
[Install]
WantedBy=multi-user.target
sample.service.start
service=sample
binary=/usr/bin/${service}
logs=/var/log/${service}
${binary} > ${logs}.out 2> ${logs}.err