Cron job

0 views
Skip to first unread message

Darrell Lee

unread,
Apr 26, 2022, 11:41:12 AMApr 26
to Upstate Carolina Linux Users Group
I have a php file on the server at my hosting company that I set up to
be run by a cron job. The script sends out a text message. It works ok
if I go the url for the php file but never has run from the cron job,
ever!

I asked the support folks at the hosting company to see if I had the
cron job set correctly and they confirmed I did; also said there were no
errors in the logs.

Is there something special about a php file that is run by cron?

--
Darrell Lee
Advanced Data Systems, Inc.
864-230-9626 | dl...@adsi-sc.com

George Law

unread,
Apr 26, 2022, 11:58:27 AMApr 26
to uc...@googlegroups.com
Shouldn't be anything special Darrel -

really just "php" and then the path to the file to run

I do it locally in a docker container - "podman_shell" is just a wrapper script I wrote that starts bash within a docker container and then passes the other command line args along ...

I have a local instance of a lamp container running spotweb - so I just use this to invoke the usenet retrieval :
*/15 * * * * /home/glaw/bin/podman_shell spotweb php  /var/www/html/retrieve.php

In the container, php is on /usr/bin/php :

root@a9178883aba9:/# which php
/usr/bin/php

And then on my centos VPS server, I have a script that I use to crawl some different free ebook pages to create a xml file
(used to push updates to a facebook page that I have using IFFTT):

0 19 * * * /usr/local/bin/php /home/geolaw/crons/books3.php > /home/geolaw/public_html/books.xml


--
You received this message because you are subscribed to the Google Groups "Upstate Carolina Linux Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uclug+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/uclug/1d7a80a4463379975b3f9791f896d2dc%40adsi-sc.com.

Darrell Lee

unread,
Apr 26, 2022, 1:16:05 PMApr 26
to uc...@googlegroups.com
Thanks George

Darrell Lee
Advanced Data Systems, Inc.

Andy Carabino

unread,
Apr 26, 2022, 5:23:46 PMApr 26
to uc...@googlegroups.com
Cron executes with a limited set of environment variables, including PATH, compared to when you run it interactively in the shell or even your web server user since you said it works via the URL.

I’ve had scripts that don’t actually error because they didn't actually run, for want of something I relied on implicitly.

Also, it’s been a while, but I am used to cron sending errors to the user’s system mailbox and not necessarily to logs — might find something there.

—Andy

Darrell Lee

unread,
Apr 26, 2022, 7:15:46 PMApr 26
to uc...@googlegroups.com
Thanks Andy

---
Darrell Lee
Advanced Data Systems, Inc.
864-230-9626 | dl...@adsi-sc.com

>> [1].
>
> --
> You received this message because you are subscribed to the Google
> Groups "Upstate Carolina Linux Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to uclug+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/uclug/18066df2248.27e9.6ecb3768cd55b08006402ae3e564851b%40adsi-sc.com
> [2].
>
> --
> You received this message because you are subscribed to the Google
> Groups "Upstate Carolina Linux Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to uclug+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/uclug/CADN2Oo_F00J4LoX%3DDRagKgnVhsU8GLorVezArtR_KWFn7niLxA%40mail.gmail.com
> [3].
>
>
> Links:
> ------
> [1]
> https://groups.google.com/d/msgid/uclug/CAKzfAU4WrTp_Jm2vdSSHLn2BzoWXZ3Q8CLLOcWmMn7BxJeKYZA%40mail.gmail.com?utm_medium=email&utm_source=footer
> [2]
> https://groups.google.com/d/msgid/uclug/18066df2248.27e9.6ecb3768cd55b08006402ae3e564851b%40adsi-sc.com?utm_medium=email&utm_source=footer
> [3]
> https://groups.google.com/d/msgid/uclug/CADN2Oo_F00J4LoX%3DDRagKgnVhsU8GLorVezArtR_KWFn7niLxA%40mail.gmail.com?utm_medium=email&utm_source=footer

shay walters

unread,
Apr 26, 2022, 11:04:37 PMApr 26
to uc...@googlegroups.com
Depending on how stripped-down a system you're running, you might not get the mail results of cron jobs.  You'll need to have a mail-handling agent installed.  I don't remember the details, but I had this happen to me and then once I loaded "mail", I started getting the mailed results from my cron jobs.  I'm not sure exactly what package it was that I installed, this was quite some time ago - "mailutils" maybe?

-Shay



Darrell Lee

unread,
Apr 27, 2022, 7:46:13 AMApr 27
to uc...@googlegroups.com
Thanks Shay

Darrell Lee
Advanced Data Systems, Inc.

Darrell Lee

unread,
Apr 27, 2022, 11:03:11 AMApr 27
to uc...@googlegroups.com
Thanks everyone for trying to help.  Inmotion support sent me a link to their Cron tutorial and I was able to get it to run ok

Darrell Lee
Advanced Data Systems, Inc.

George Law

unread,
Apr 28, 2022, 12:39:27 PMApr 28
to uc...@googlegroups.com
Darrel and all,

I know you said your web host got you all fixed up, but Just another example since I just
have been building a local fedora ZFS server and setting up the scrubs and things :

I used this set up to configure my local server to relay through my gmail account :
I had to create an "app specific password" in the google security settings - and I think there is

Then my cron to run at 12:21 - 
# crontab -l
MAILTO=geol...@gmail.com
#0 2 1 * * /usr/sbin/zpool scrub files
21 12 * * * /usr/sbin/zpool status

and then boom - (some headers removed)
From: "(Cron Daemon)" <geol...@gmail.com>
To: geol...@gmail.com
Subject: Cron <root@dell> /usr/sbin/zpool status
Date: Thu, 28 Apr 2022 12:21:02 -0400 (EDT)

  pool: pool1
 state: ONLINE
  scan: scrub in progress since Thu Apr 28 12:17:55 2022
	263G scanned at 1.41G/s, 984K issued at 5.26K/s, 754G total
	0B repaired, 0.00% done, no estimated completion time
config:

	NAME        STATE     READ WRITE CKSUM
	pool1       ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sde     ONLINE       0     0     0
	    sdc     ONLINE       0     0     0

errors: No known data errors

  pool: pool2
 state: ONLINE
config:

	NAME        STATE     READ WRITE CKSUM
	pool2       ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sdb     ONLINE       0     0     0
	    sdd     ONLINE       0     0     0

errors: No known data errors

So you can also do it from a local machine if need be

*sorry for any typos - my eyes have been dialated and everything is fuzzy :)
~George


George Law

unread,
Apr 28, 2022, 1:42:10 PMApr 28
to uc...@googlegroups.com
and if anyone's interested in the postfix + gmail setup,I've ansibled it

the main.cf file is from fedora, not sure how portable it is to debian/ubuntu/suse/X
All I really did is add the last 6 lines onto the file, so
something like this could be used to make it more disto agnostic :
    - name: Insert a line at the end of a file.
      lineinfile:
        path: /Users/mdtutorials2/Documents/Ansible/line.txt
        line: last


Reply all
Reply to author
Forward
0 new messages