Derek_ Posted December 29, 2019 Share Posted December 29, 2019 (edited) Hi everyone, I've NEVER used Cron before, so i'm struggling with everything about it. Here's what i would like to do: 1. Set a custom BASH script to run once a week (it will run checks and prunes on backups), at a certain time - say midnight Monday. 2. If the server is not up at that time (it's not a 24x7 server), then run it at the next opportunity (i.e. when the server is next turned on). 3. Do not run it again until the next scheduled time (midnight Monday). 4. Run the script as a specified user (i.e. not root or nobody - in my case the backup-user). Is that possible? I've searched the forums, it doesn't look like many people use Cron (or they know how to use it! ) - i haven't found anything that helped me except this post from @tmchow. It at least pointed to using his 3rd choice which seemed the better approach. Quote 3. Put cron scripts into /boot/config somethere (e.g. /boot/config/plugins/custom_cron/). These scripts are all automatically loaded on system start into /etc/cron.d/root/. If you make changes and want them applied, just run the command update_cron which reloads all the custom crons in /boot/config/plugins/custom_cron/). Thanks in advance. Edited December 29, 2019 by Derek_ Quote Link to comment
tmchow Posted December 29, 2019 Share Posted December 29, 2019 Hi everyone, I've NEVER used Cron before, so i'm struggling with everything about it. Here's what i would like to do: 1. Set a custom BASH script to run once a week (it will run checks and prunes on backups), at a certain time - say midnight Monday. 2. If the server is not up at that time (it's not a 24x7 server), then run it at the next opportunity (i.e. when the server is next turned on). 3. Do not run it again until the next scheduled time (midnight Monday). 4. Run the script as a specified user (i.e. not root or nobody - in my case the backup-user). Is that possible? I've searched the forums, it doesn't look like many people use Cron - i haven't found anything that helped me except this post from@tmchow. It at least pointed to using his 3rd choice which seemed the better approach. 3. Put cron scripts into /boot/config somethere (e.g. /boot/config/plugins/custom_cron/). These scripts are all automatically loaded on system start into /etc/cron.d/root/. If you make changes and want them applied, just run the command update_cron which reloads all the custom crons in /boot/config/plugins/custom_cron/). I actually just updated that post to say I use option 4 which is the user scripts plugin. Far better and easier way to manage scripts you need to run. Highly recommended. Quote Link to comment
Derek_ Posted December 29, 2019 Author Share Posted December 29, 2019 1 minute ago, tmchow said: I actually just updated that post to say I use option 4 which is the user scripts plugin. Far better and easier way to manage scripts you need to run. Highly recommended. LOL, no fair! Will option 4 do what i would like it to do? Like you state, there's no granularity with the scheduling. When this activity happens matters, i don't want to prune while backups are running, or while a parity check is happening etc. Quote Link to comment
tmchow Posted December 29, 2019 Share Posted December 29, 2019 LOL, no fair! Will option 4 do what i would like it to do? Like you state, there's no granularity with the scheduling. When this activity happens matters, i don't want to prune while backups are running, or while a parity check is happening etc. I updated the post to say that it does now have granularity. You have full granularity of cron schedules but you can also pick dummy proof schedules like- run at array start- run daily- run hourlyEtc 1 Quote Link to comment
Derek_ Posted December 29, 2019 Author Share Posted December 29, 2019 3 minutes ago, tmchow said: updated the post to say that it does now have granularity. You have full granularity of cron schedules but you can also pick dummy proof schedules like Ahh, ok. I'll look at it more closely. Thanks. Do you know how to run the script as a particular user, rather than root? Quote Link to comment
Squid Posted December 29, 2019 Share Posted December 29, 2019 16 hours ago, Derek_ said: while backups are running, You'd have to add in appropriate tests to determine that in your scripts 16 hours ago, tmchow said: or while a parity check is happening etc. The plugin can handle that for you https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/?tab=comments#comment-475625 16 hours ago, Derek_ said: Do you know how to run the script as a particular user, rather than root? All scripts are executed as root. Either start a sub-script running as a particular user, or issue the appropriate chmod / chown commands after you're done. Should be noted however that on occasion you may need to specify full paths to commands that you may not have to when executing from the shell. IE: environment variables that are set in the shell aren't utilized in the plugin. 1 Quote Link to comment
Derek_ Posted December 30, 2019 Author Share Posted December 30, 2019 (edited) 13 hours ago, Squid said: You'd have to add in appropriate tests to determine that in your scripts The plugin can handle that for you https://forums.unraid.net/topic/48286-plugin-ca-user-scripts/?tab=comments#comment-475625 All scripts are executed as root. Either start a sub-script running as a particular user, or issue the appropriate chmod / chown commands after you're done. Should be noted however that on occasion you may need to specify full paths to commands that you may not have to when executing from the shell. IE: environment variables that are set in the shell aren't utilized in the plugin. Hi Squid. Good to see it will not conflict with parity check. I've done some research, and i think we can run the script that cron invokes as another user. I'll avoid the chown route if i can. I'm exhausted right now learning about BASH and systemd, so this cron stuff will have to take a back seat for a bit... depends how long it takes me to come to grips with what i'm already working on. Pity i can't utilise my systemd configurations in Slackware-based unRAID. Here's the run as another user info: https://www.lostsaloon.com/technology/how-to-run-cron-jobs-as-a-specific-user/ I presume everyone who needs it either worked it out, or there's little demand for it, but that might be an ok idea for a feature enhancement. As an aside, i've added my tinny voice to the request to put anacron in the base build, and i've also asked the NerdPack guys if they could add it, because the feature request to LimeTech was from 2016 Thanks. Edited December 30, 2019 by Derek_ Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.