0

Running on ubuntu18, have a bash job to collect data from a router using ansible. Here is the bash script

#!/bin/bash
cd ~/datacollect
ansible-playbook -i /home/user/datacollect/hosts /home/user/datacollect/datacollect.yml

If I run the bash job from ubuntu console, there is no issue. Since we need to collect data every 5 minutes, I created a cron job for it.

* * * * *  /home/user/datacollect/call.sh

The data was not saved to the output file, at the beginning, I thought something stopped the cron job to run, then I found the information from /var/mail/user

Subject: Cron <user@host> /home/user/datacollect/call.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/user>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=user>
Message-Id: <20211008092301.EB6B8262437@host>
Date: Fri,  8 Oct 2021 20:23:01 +1100 (AEDT)

/home/user/datacollect/call.sh: line 3: ansible-playbook: command not found

It may be related to path environment setup as below, but I am not sure how to check and modify and not sure if it is the root cause. -bash: ansible-playbook: command not found

  • In the cron job, I have to specify the path as below to make it work PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin – chun xu Oct 10 '21 at 09:51

0 Answers0