OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 20.7 Legacy Series »
  • User created cron job issues
« previous next »
  • Print
Pages: [1]

Author Topic: User created cron job issues  (Read 1406 times)

unixpgmr

  • Newbie
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
User created cron job issues
« 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?
Logged

siga75

  • Full Member
  • ***
  • Posts: 180
  • Karma: 11
    • View Profile
    • www.signorini.ch
Re: User created cron job issues
« Reply #1 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
Logged
https://www.signorini.ch (please do hack me contest)
OPNsense 20.7 on
Protectli Pfsense Mi7500L6 Intel 7Th Gen Core I7 7500U 16Gb Ddr4 Ram
512Gb Msata Ssd
6 X Intel Gigabit Ethernet

unixpgmr

  • Newbie
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: User created cron job issues
« Reply #2 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.
« Last Edit: November 03, 2020, 03:39:53 am by unixpgmr »
Logged

unixpgmr

  • Newbie
  • *
  • Posts: 14
  • Karma: 1
    • View Profile
Re: User created cron job issues
« Reply #3 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. 
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 20.7 Legacy Series »
  • User created cron job issues
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2