I have a very strange situation.
I have a systemd unit
[Unit]
Description=Nightly snapshot backup job for [%i] volume
[Service]
Type=simple
KillMode=process
EnvironmentFile=/etc/systemd/schedule-backup_%i.conf
ExecStart=/usr/local/bin/backup.sh -s '$SOURCE' -b '$BACKUP' -t '$TITLE' -l 'backup_%i.log'
When I execute that with the service instance:
sudo systemctl start [email protected]
the backup.sh script does not receive the last parameter at all. It should get "backup_projects.log"
I am reading the parameters with
while getopts s:b:t:l: flag
do
case "${flag}" in
s) source_path_root="${OPTARG}";;
b) backup_path_root="${OPTARG}";;
t) email_title="${OPTARG}";;
l) log_name="${OPTARG}";;
esac
done
when I check the service logs, it seems the script is called with the appropriate parameters:
systemctl -l status [email protected] -n50
○ [email protected] - Nightly snapshot backup job for [projects] volume
Loaded: loaded (/etc/systemd/system/[email protected]; static)
Active: inactive (dead) since Tue 2021-12-14 12:47:01 EET; 16min ago
TriggeredBy: ● schedule-backup_projects.timer
Process: 8161 ExecStart=/usr/local/bin/backup.sh -s $SOURCE -b $BACKUP -t $TITLE -l backup_projects.log (code=exited, status=0/SUCCESS)
Main PID: 8161 (code=exited, status=0/SUCCESS)
CPU: 3.122s
Dec 14 12:46:56 fallen-robot systemd[1]: Started Nightly snapshot backup job for [projects] volume.
Dec 14 12:46:56 fallen-robot backup.sh[8161]: /usr/local/bin/backup.sh: line 37: /var/log/: Is a directory
Dec 14 12:46:56 fallen-robot backup.sh[8161]: Log file set to /var/log/
When I execute the same script from the console the parameter is accepted fine. What am I doing wrong?
EDIT: Seems like it worked once I put the -l parameter in the beginning instead of at the end. Could be some problem with getopts. I will accept an answer from whoever can explain this