glpi-project / glpi-agent

GLPI Agent
GNU General Public License v2.0
212 stars 51 forks source link

Wrong variable(s) in GLPI agent cron file for DEB-based distros when installing via installation script #692

Closed djanjusevic-srce closed 2 weeks ago

djanjusevic-srce commented 2 weeks ago

Bug reporting acknowledgment

Yes, I read it

Professional support

None

Describe the bug

When installing GLPI agent via installation script (1.7.3, 1.8 or 1.9 tested) on DEB-based OS (tested on Ubuntu 22.04, Debian 10, 11 and 12), I end up with the cron file in /etc/cron.hourly containing

NAME=glpi-agent-cron
LOG=/var/log/$NAME.log

Few lines below, same cron file is trying to source the following:

[ -f /etc/default/$NAME ] || exit 0
source /etc/default/$NAME

which doesnt' exist since variable NAME is set to "glpi-agent-cron" instead of "glpi-agent".

Also, installation script forces LOG variable to be /var/log/$NAME.log in cron file no matter what options you give to script when installing.

I suggest the following:

1) Set NAME variable in cron file to "glpi-agent" 2) Make LOG either a) respect the corresponding commandline option given to script or b) set it to /var/log/$NAME/$NAME.log to be consistent with RPM-based installations.

To reproduce

# perl glpi-agent-1.9-linux-installer.pl --local=/root/inventory.json --no-task=deploy,remoteinventory --no-p2p --no-ssl-check --no-httpd --logger=file --logfile=/var/log/glpi-agent/glpi-agent.log --cron --type=inventory --silent
# /etc/cron.hourly/glpi-agent (run cron)
# cat /var/log/glpi-agent-cron.log (empty log file)
# ls -l /path/to/inventory (doesn't exist)

Expected behavior

Cron job should produce the inventory file in /root/inventory.json

Operating system

Linux

GLPI Agent version

1.9, 1.8, 1.7.3

GLPI version

10.0.11

GLPIInventory plugin or other plugin version

GLPI Inventory v1.3.5

Additional context

No response

g-bougard commented 2 weeks ago

Hi @djanjusevic-srce

thank you for your report.

Yes, NAME should not be set to glpi-agent-cron, but glpi-agent.

The LOG var here is only there to log cron task execution and any eventual stderr output from started script.

So I'll modify the installer to set in front of the /etc/cron.hourly/glpi-agent script:

NAME=glpi-agent
LOG=LOG=/var/log/$NAME-cron.log
djanjusevic-srce commented 2 weeks ago

Thank you @g-bougard for the quick answer; You are definitely right, log file location or name are not crucial for successfully executing the cron job, but NAME variable is.

Cheers, Dragan

g-bougard commented 2 weeks ago

Hi @djanjusevic-srce

next nightly build should work as expected.