Answer the question
In order to leave comments, you need to log in
How to run a bash script as a daemon in systemd?
There is a script for monitoring the file system
/root/.bin/monitor.sh
inotifywait -e create,delete,modify,move -mrq /tmp/mydir | while read events
do
echo "$(date +"%m.%d.%Y_%T") $events" >> /var/log/files.log
done
[Unit]
Description=Monitoring file systems
DefaultDependencies=no
Wants=network.target
After=local-fs.target network.target systemd-sysctl.service systemd-modules-load.service
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target
[Service]
Type=oneshot
ExecStart=/root/.bin/monitor.sh
ExecStop=
RemainAfterExit=true
TimeoutStartSec=5min
Answer the question
In order to leave comments, you need to log in
Solved a problem.
#!/bin/bash -
#ссылка на интерпретатор обязательна
function monitoring() {
inotifywait -e create,delete,modify,move -mrq $1 | while read events
do
echo "$(date +"%m.%d.%Y_%T") $events"
done
}
DIR="%mydir%"
LOGFILE="%mylogfile%"
echo "Start filesystem monitoring: Directory is $DIR, monitor logfile is $LOGFILE"
monitoring $DIR >> $LOGFILE &
[Unit]
Description=File system Monitoring -- /root/.bin/monitor.sh
After=local-fs.target systemd-sysctl.service systemd-modules-load.service
[Service]
Type=forking
ExecStart=/root/.bin/monitor.sh
EnvironmentFile=/root/monitor.cfg
[Install]
WantedBy=multi-user.target
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question