How to use crond instead of atd? - linux

I have an embedded device running busybox. The device has crond installed and running, but has no atd daemon. I need to schedule task to run at a given time (just once, not periodically). I know, that the "kosher" way is to use at command, but I unfortunately don't have one. So, how can I use cron as a workaround?

You can set up the cron to run your script, and when it succeeds, the script should just comment out or remove the cron entry.

Related

Alternative to #reboot for busybox crond?

I'm trying to run a script at startup using busybox, but I've read that #reboot isn't supported with my version of cron. I need to use cron for this rather than running the script some other way. Is there an alternative solution to getting it to run at startup with crond and crontab?
#reboot can be implemented in Busybox by using /etc/init.d/local (& placing the scripts in /etc/local.d).
It can also be done by altering /etc/init.d/crond.

Synology - Cron job

I'm trying to make cron jobs or task schduler working, but I can not figure out why my script is not taken in consideration.
I'm trying to simply archive a folder with:
tar -cvf /volume1/NetBackup/Backups/Monday.tgz /volume1/NetBackup/Backups/ns3268116.ovh.net/
Each time the script starts working but cannot achieve the work. Either with task scheduler or crontab, a file Monday.tgz is created in folder /volume1/NetBackup/Backups/, but this file is only 1024 bytes.
Synology Cron is really fussy.
Here are my own personal notes for Synology DS413j, DSM 5.2:
Hand edit /etc/crontab as root, crontab -e isn't available
Ensure you use tabs not spaces to separate the columns
Your crontab changes may not survive a reboot if there are syntax problems
The who column in crontab may not be reliable. Use root in the who column and /bin/su -c '<command>' <username> to run as another other user
remember that it uses ash not bash so check for bashisms, e.g use >> /path/to/logfile 2>&1' not&>> /path/to/logfile`
It doesn't support 'MAILTO='
you need to restart crond synoservicectl --reload crond for the new crontab to take effect
You may try adding some diagnostics to it. For instance:
Add MAILTO into the crontab file (on top of crontab -e) to receive cron errors by email:
MAILTO=username#domain.com
Redirect output of your tar command to the file:
your command > ~/log.txt 2>&1
Check cron log and look for anomalies. For instance (it may depend on your configuration):
/var/log/cron.log
You may also try searching through /var/log/messages at the time of your cron job.
Is volume1 a resource on remote host? If yes, it is worth checking this part of the system.
I agree about the really nagging nature of Crontab on Synology Linux OSs.
I would certainly suggest to create de desired job as a .sh shell script and call it via CRON task inserted by using the GUI, as suggested here.
As for today (March 2017) is the best method I have found, since working with crontab via CLI is nearly a pain.

Cron scheduled task ignored

I have set a specific cronjob (crontab -e), but it doesn't works like I thought. I don't get what's wrong.
Here is what I do (root cron):
#reboot /path/to/my_script.sh start
25 18 * * * halt
The first line as expected is running my_script.sh, but when time comes for the server to shutdown, nothing happen. Is the #reboot option made to work alone?
There is no option in cron to run at shutdown. #reboot is meant to run the script on start
If you want to run a script at shutdown, you need to write an initd script and register it for the shutdown run level. The standard runlevel for halt is 0, the run level for restart is 6. I've verified this for Debian, Gentoo and Redhat systems but it seems to be true across *NIX systems. Check this for more info.

restart cron service script with non root user aix

I need to make a batch that restart cron service on aix system,but it must be done with non root user??
I need to do so because in aix you must restart cron service when modifying crontab file, in order to accepts the new changes..
Best regards,
Use the crontab command to submit the updated cron file. It will signal crond to reload/reset.

Difference between nohup vs at now

It seems that there is no difference between nohup and at now, but maybe there are subtleties?
The difference is that now runs a command that can respond to HUP signal, where as the nohup runs a command that is immune to HUP signal.
Ed Heal is right. But another difference is that something run by nohup still has a controlling terminal, whereas something run by at now does not.
In addition to that, backgrounding something with nohup causes it to run immediately, whereas at now simply queues something to be run the next time atrun(8) runs. In BSD unix, (FreeBSD/OpenBSD) at jobs are launched by atrun which is launched periodically by cron (or launchd in OSX). In Linux, at jobs are run by at's own daemon, atd, which by default launches jobs every 60 seconds.
Other flavours of unix may have different strategies, but in most cases you'll probably find that jobs launched by at now are less immediate than jobs launched using nohup.
nohup tells the system to continue running even after you log out.
at is used to execute a command or multiple commands once at some future time.

Resources