How do I get cron working inside a web server container?

I am getting used to NS8 container but am having trouble understanding what I need to do to get a cron job to run a php script regularly. I can see my site in the user home. I have also found it with run agent on that user then podman for php where php is live but no cron in there. I don’t want to hose up anything vital so have been researching and finally asking here.

It’s explained here:

2 Likes

Thank you, I read that before posting. crontab -e is not available, though I may be invoking it incorrectly. At the top level of the system, I can use crontab -e. I put the following in (with “ root “ after the “*****”) but no joy. I put this into a file in cron.d:

***** /usr/local/bin/runagent -m webserver2 – /usr/bin/podman exec php8.4-fpm /usr/local/bin/php /var/www/html/9001/tfv/scripts/tfv.php >> /var/log/tfv.log 2>&1

I have yet to see it run from there. I can run the command line from bash manually and do see logs. Frustrated with myself at the slow learning of how many abstractions there are and what can do what where. Today, I updated the core and now the system is not accepting connections through the NAT. It was working fine yesterday and I don’t know what I did. Just venting a little. I appreciate your response.

Do you get an error? Here it’s available as root and as webserver1 user.

Here it works as root but there’s no need to put it to cron.d.

As root execute crontab -e which should open an editor.

I added

* * * * * runagent -m webserver1 podman exec -ti php8.4-fpm php /var/www/html/9001/phpinfo.php > /var/log/logfile

and after 1 minute the file logfile was created in /var/log

The same works in the webserver instance environment.

Enter webserver environment:

runagent -m webserver1

Edit crontab:

crontab -e

Add a line

* * * * * podman exec -ti php8.4-fpm php /var/www/html/9001/phpinfo.php > logfile

and after 1 minute I can see the file logfile in /home/webserver1/

How did you update and from which version?
Does it mean the webserver isn’t reachable via port forwarding from public anymore? Is it still reachable from LAN?

I appreciate the assistance. I need to get all the information you requested. On the update it was through the web admin software center. It had a notice core needed to be updated so I did. I was only able sign on to it locally (I did through VPN). After several reboots I was able to access it remotely again. This has happened several times now that I’m paying attention. I notice it when the email server stops accepting connections. I want to disable crowd sec to see, but for a nothing server, it gets slammed with constant attacks so I don’t want to just yet. Getting errors and versions for you.

1 Like

I worked it out. It came down to a hypothetical example I gave years ago that came true. I generally use nano for small text edits. Somehow, the hyphens in the cronjob were unicode – (en dash, U+2013)… yeah. Not an ascii or even UTF-8 “-” and nano doesn’t indicate unicode. I was against unicode in programming when it was introduced for just this case. A lot of lost time for an incredibly obscure issue. I had thought nano forced UTF-8 but guess not. I appreciate the assistance. The solution you helped with with was the “other eyes” prodding my mind. Thank you.

2 Likes