OPNsense Forum

Archive => 20.7 Legacy Series => Topic started by: unixpgmr on November 01, 2020, 09:49:03 pm

Title: User created cron job issues
Post by: unixpgmr on November 01, 2020, 09:49:03 pm
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
Code: [Select]
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:
Code: [Select]
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?
Title: Re: User created cron job issues
Post by: siga75 on November 02, 2020, 08:28:05 am
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
Title: Re: User created cron job issues
Post by: unixpgmr on November 03, 2020, 03:15:05 am
There is nothing in /var/log/configd older than Oct 13.
Here is the script that is being executed:
Code: [Select]
#!/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:
Code: [Select]
# 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.
Title: Re: User created cron job issues
Post by: unixpgmr on November 03, 2020, 04:55:34 am
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.