User created cron job issues

Started by unixpgmr, November 01, 2020, 09:49:03 PM

Previous topic - Next topic
I have a cron job that lets me know when a user has logged in to my firewall. I have been following this:
https://docs.opnsense.org/development/backend/configd.html
Here are the particulars:
in usr/local/opnsense/service/conf/actions.d I have the following
cat actions_getwho.conf
[update]
command:/home/mts/cron_scripts/getWho.sh
parameters:
type:script
description: Check for logged in users
message:get who is logged in.

I perform the following:
service configd restart
configctl getwho update

on the command line.  I get a notice about who is logged in. I set the cron job in the interface. Nothing happens.

I am at a loss
Anybody have any idea what is going on?

do you see something strange in the last log in /var/log/configd?

what's the content of /home/mts/cron_scripts/getWho.sh?

it could be just an environment issue, maybe in the PATH variable
https://www.signorini.ch
Protectli Pfsense Mi7500L6 Intel 7Th Gen Core I7 7500U 16Gb Ddr4 Ram
512Gb Msata Ssd
6 X Intel Gigabit Ethernet

November 03, 2020, 03:15:05 AM #2 Last Edit: November 03, 2020, 03:39:53 AM by unixpgmr
There is nothing in /var/log/configd older than Oct 13.
Here is the script that is being executed:
#!/usr/local/bin/bash
baseDir="/home/mts/cron_scripts/"
errFile="/tmp/users.err"
cronFile="/tmp/getWho.cron"
users=$(/usr/bin/who -a)
if [ ${#users} -gt 0 ]; then
  ${baseDir}discordPush.sh "ALARM: ${users} logged on"
  touch ${errFile}
else
  if [ -f ${errFile} ]; then
    ${baseDir}discordPush.sh "OK: Users have logged off"
    rm ${errFile}
  fi
fi
echo "OK" > ${cronFile}
echo 0

Like I said in my previous post. It works when I do a configctl getwho update.  However, it never works after that. It is like the cron system doesn't even see it. However, when I look in /var/cron/tabs/nobody, I see the following:

# Origin/Description: cron/Checking for logged in users
2 * * * * /usr/local/sbin/configctl getwho update

Also, if I run the cron command by hand, it works just fine.

I finally got it to work. I was totally and utterly stupid.  I wanted it to run every two minutes...not two minutes after each hour. I think I did find an odd bug. I need to do more testing first.