• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Need help with cron tab

cipcip

Basic Pleskian
Hi guys,

I need help setting up a crontab on my plesk server. It seems that I cannot get it to work :( ...

I am using:
*/5 * * * * pgrep -f main.py || nohup python3 cd /var/www/vhosts/criago.com/httpdocs/pie/main.py >> /var/www/vhosts/criago.com/httpdocs/pie/freakin.log

So basically, I want it to run / check every 5 minutes to see if my script is running. If is not running, start it, if it is running skip.

The log files is not getting created and the cron never starts. I am testing with:
ps ax | grep main.py

What I get ?

27781 ? Ss 0:00 /bin/sh -c pgrep -f main.py | pgrep python3 || nohup python3 /var/www/vhosts/criago.com/httpdocs/pie/main.py > test.out
27785 ? S 0:00 python3 /var/www/vhosts/criago.com/httpdocs/pie/main.py
29506 pts/0 S+ 0:00 grep --color=auto main.py

One other thing, I do not understand why I have multiple entries ? How can I delete the extra ones ? Because if I open the file under: /var/spool/cron/crontabs/root , I only have the one that I am using there, not the old ones anymore.

I also tried to use: sudo service cron reload - but it is not starting or the old ones are not being removed.

Thank you,
Cristian.
 
I couldn't get cron to work so I did it using a service.

I have created the file testing.service in /etc/systemd/service/ with:

[Unit]
Description=my criago service crawler
After=multi-user.target

[Service]
Type=idle
User=root
ExecStart=/usr/bin/python3 /var/www/vhosts/criago.com/httpdocs/pie/main.py
Restart=always
TimeoutStartSec=10
RestartSec=10

[Install]
WantedBy=multi-user.target

Then ran the following commands in Putty:

sudo systemctl daemon-reload

sudo systemctl enable testing.service

sudo systemctl start testing

Seems to do the trick. But this is really the correct approach ?

Thank you,
Cristian
 
Back
Top