Write and schedule a job on Unix server which is triggered even after the server restart

Viewed 27

I'm trying to create a task on Unix similar to a task of Task Scheduler in Windows which will run at specific times of the day and even gets triggered after server restarts. Aim of this job is to execute a python file. My question is two parts:

1). How to write a job which I can schedule at multiple times of the day. I tried to write cron job using crontab command but it gives You <user> are not allowed to access to (crontab) because of pam configuration. I would like to know a way where I can schedule the triggering of python script without needing root/admin rights.

2). How can I schedule a job whose scheduling stays in effect even after the server is restarted. While going through various resources, I found systemd, using which we can use to start and stop the services. For example, https://linuxconfig.org/how-to-write-a-simple-systemd-service#:~:text=%20How%20To%20Write%20A%20Simple%20Systemd%20Service,section%20that%20you%20need%20to%20w...%20More%20 .But I'm unable to find how i can write a service script which will run my python script.

Can someone please guide on how can I run a job which executes my python script a some specific times of day and keeps working even after server bounce.

1 Answers

First PAM error say you do not have permissions so check /etc/security/access.conf and add line

+ : youruser : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6

For exec cron job on boot add in cron line like this:

@reboot  /path/to/your_program
Related