Cron Help! Need to edit a coldreboot command

Slow way:
Code:
find / -name coldreboot
Fast way (if you have mlocate and an up to date database)
Code:
locate coldreboot
Fast way (if it's in your current PATH variable)
Code:
which coldreboot

No, that should be fine too. I didn't say anything about crontab -e.
(locate is not found)
Code:
which coldreboot
returns:
Code:
/sbin/coldreboot

I tried editing the crontab -e, and it gives an error after trying to save it:
1. I open crontab -e
2. As the very last line, I added
Code:
echo "*/10 * * * * root coldreboot" >> /etc/crontab
3. Whilst saving it asks for confirmation on
Code:
File Name to Write: /tmp/crontab.vRAQPb/crontab
4. I press enter (that path seems wrong no? But I had no choice but to say yes to the default, whats do I know)
5. Error:
Code:
no crontab for root - using an empty one
crontab: installing new crontab
" /tmp/crontab.vRAQPb/crontab":22: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?

And thats where I am with that.

All this seems awfully convoluted and complicated for my desire to add one little command to reboot a rig every x minutes. I just thought Linux would excel in executing something like this..... :confused:
 
If you're directly editing a cron job file you do not need to add the echo part. That will cause a syntax error which is the "errors in crontab file" message you're seeing. Just enter the contents of the double quotes and use the full path for coldreboot even though it may not be necessary (just to be safe).

so:

*/10 * * * * root /sbin/coldreboot

Should be your entry.
 
If you're directly editing a cron job file you do not need to add the echo part. That will cause a syntax error which is the "errors in crontab file" message you're seeing. Just enter the contents of the double quotes and use the full path for coldreboot even though it may not be necessary (just to be safe).

so:

*/10 * * * * root /sbin/coldreboot

Should be your entry.

Ok that worked without an error, but still didnt execute.. what about the refresh/reboot? Just reboot the system or do I need to execute another command line?
 
Rebooting or restarting cron with 'service' will work.

Just rebooting the system didnt work... nor did
Code:
service cron restart
(even though that did confirm with "Restarting perdiodic command scheduler: cron.")

When I do a crontab -l it does show at the very bottom

Code:
*/5 * * * * root/sbin/coldreboot

So I am befuddled yet again.
 
Just rebooting the system didnt work... nor did
Code:
service cron restart
(even though that did confirm with "Restarting perdiodic command scheduler: cron.")

When I do a crontab -l it does show at the very bottom

Code:
*/5 * * * * root/sbin/coldreboot

So I am befuddled yet again.

There should be a space between the user name (root) and the program to run. I imagine that would have thrown a syntax error when trying to save though.
 
There should be a space between the user name (root) and the program to run. I imagine that would have thrown a syntax error when trying to save though.

Added the space, tried restarting cron and hard reboot of whole rig, still not working.
 
If you enter does the system restart?

Code:
This system is going down for a reboot now!

and yes, it reboots after that.......

There are some others guys talking about something similar, although nothing exactly like this, but they were listing commands such as

(to reboot BAMT, like a reset button)
Code:
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

(another solution for reset, like what we are doing)
Code:
sync;coldreboot

Just thought I would add, maybe it will set off some helpful light bulbs for my case......
 
Perhaps test that cron works at all on your distro. Try something very simple such as echoing some text into a text file and see if it creates the file and appends new lines. e.g.

Code:
* * * * * root echo "Is cron working?" >> /tmp/file.txt

This does work on two of my systems after being entered into crontab and restarting cron.
 
Perhaps test that cron works at all on your distro. Try something very simple such as echoing some text into a text file and see if it creates the file and appends new lines. e.g.

Code:
* * * * * root echo "Is cron working?" >> /tmp/file.txt

This does work on two of my systems after being entered into crontab and restarting cron.

If cron doesnt work, how did my initial command work per my OP? Is that a totally different command process?

When I type in your code verbatim, it is a negative:
Code:
bash: Desktop: command not found

So do I have to do something to set the right command path? Or is there another problem.....

Thanks for sticking with me btw and helping... I cant believe this is so intricate.... almost feel like just burning a whole new drive and typing that initial command that worked in with the proper 60 minutes instead of something else, because that worked flawlessly.
 
If cron doesnt work, how did my initial command work per my OP? Is that a totally different command process?

Well we know you blew away your crontab which is a huge problem if that was never fixed. Unfortunately, we do not know if anything else happened to the configuration that could be detrimental so we're kind of guessing at this point. Could you post the entirety of your /etc/crontab? SHELL and PATH should both be defined in it (directly related to jwcalla's last post).

When I type in your code verbatim, it is a negative:
Code:
bash: Desktop: command not found

So do I have to do something to set the right command path? Or is there another problem.....

The word "Desktop" isn't in my post at all.
Code:
echo "Is cron working?" >> /tmp/file.txt

This should result in the creation of /tmp/file.txt with the line "Is cron working?" or the same text appended to the next line of the file if it already exists. Where did "Desktop" come from? Could you post a screenshot of what you're trying to run?

Thanks for sticking with me btw and helping... I cant believe this is so intricate.... almost feel like just burning a whole new drive and typing that initial command that worked in with the proper 60 minutes instead of something else, because that worked flawlessly.

Sadly, it really isn't intricate. The problem is that something is wrong with your configuration and we're taking stabs in the dark to figure out that may be. :/
 
jwcalla is probably right.
I've downloaded bamt 1.5 (I think...) from here. Let me/us know if that's not it.

Here is the default /etc/crontab
Code:
user@bamt-miner:/etc$ cat crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
MAILTO=""
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
* * * * *       root    /opt/bamt/mother
30 0 * * *      root    /usr/sbin/ntpdate ntp-0.cso.uiuc.edu
35 0 * * *      root    rm /tmp/*.log

The PATH= line sets what directories should be searched when a command is issued by cron that doesn't explicitly give the full path.
An example of how this works would be copying with the 'cp' command. When you type "cp thisFile thatFile" it will look at the PATH variable and look in all of those directories for the 'cp' command.
Same thing except this sets if for commands that cron will issue.

Lets find out where coldreboot lives:
Code:
user@bamt-miner:~$ whereis coldreboot
coldreboot: /sbin/coldreboot /usr/share/man/man8/coldreboot.8.gz

coldreboot lives in /sbin/ and we can look at the PATH and see that /sbin/ is in the path. So normally you can just list the command in cron as 'coldreboot' and it will find it and execute it.
Through all of the echo-fu that was going on, your crontab is likely empty or at least lacking in setting the environment variables that get set before commands are run. You'll need to get that straightened out.


There's also been some guessing as to what cron is doing, when it's doing it, and what the results are. You can check the log file and probably find a lot of useful information. It's located in /var/log/cron.log
Code:
user@bamt-miner:/var/log$ sudo cat cron.log
Feb 15 21:21:06 bamt-miner /usr/sbin/cron[2683]: (CRON) INFO (pidfile fd = 3)
Feb 15 21:21:06 bamt-miner /usr/sbin/cron[2704]: (CRON) STARTUP (fork ok)
Feb 15 21:21:06 bamt-miner /usr/sbin/cron[2704]: (CRON) INFO (Running @reboot jobs)
Feb 15 21:22:01 bamt-miner /USR/SBIN/CRON[3492]: (root) CMD (/opt/bamt/mother)
Feb 15 21:23:01 bamt-miner /USR/SBIN/CRON[3600]: (root) CMD (/opt/bamt/mother)
Feb 15 21:24:01 bamt-miner /USR/SBIN/CRON[3653]: (root) CMD (/opt/bamt/mother)
Feb 15 21:25:01 bamt-miner /USR/SBIN/CRON[3727]: (root) CMD (if [ -x /etc/munin/plugins/apt_all ]; then /etc/munin/plugins/apt_all update 7200 12 >/dev/null; elif [ -x /etc/munin/plugins/apt ]; then /etc/munin/plugins/apt update 7200 12 >/dev/null; fi)

Good job sticking with it! You're really learning linux the hard way. Jumping into editing service config files isn't normally someone's first experience. Doubly so on a distro where the boot splash screen is doge.
 
Last edited:
^-- That's the file you need. Copy and paste it into your /etc/crontab and then add your coldreboot line at the very bottom. Follow the pattern exactly -- no echos and no quotes.

Save the file and then run "service cron restart".

Don't use "crontab -e". If you want to modify the crontab in the future, use "nano /etc/crontab" or open the file up in one of the graphical text editors.
 
Hey guys... not ignoring you, just was busy working long hours on set for last 3 days and wiped out...

And I was trying some different versions of BAMT to check out some results, so after installing other versions, I just tried the

Code:
nano /etc/crontab

then adding at the end of the file

Code:
*/3 * * * * root /sbin/coldreboot

then executing

Code:
service cron restart

to test (didnt have 60 minutes to wait to see if it worked, now that I know how to edit cron)

and it seems like it is working... but weird (why should this work perfectly with my luck), at first it gave me an error when I tried to get back into file manager or terminal after the 3 minute reboot to change to 60... sorry I forgot the precise lexicon but it was like a user not authorized error... had to do a hard power reboot, and then it was fine, and I changed it to 60... I guess I'll confirm with myself tomorrow if it actually does reboot every 60 minutes now.

Sorry I couldnt continue testing the other stuff, but at least now I have learned what cron is, how to edit and do time related commands and have a better understanding of this thing... I'm sure u guys will live knowing that, LMAO...... hopefully this is the last u hear from me about this topic. :D
 
On this topic, if

*/59 * * * * root /sbin/coldreboot

means every 59 minutes, how do I change that to like 150 minutes, or 2 hours etc...?
 
...

Code:
Minute   Hour   Day of Month       Month          Day of Week             Command
(0-59) (0-23)    (1-31)        (1-12 or Jan-Dec)   (0-6 or Sun-Sat)
0      */12          *            *                *                   /usr/bin/find
 
...

Code:
Minute   Hour   Day of Month       Month          Day of Week             Command
(0-59) (0-23)    (1-31)        (1-12 or Jan-Dec)   (0-6 or Sun-Sat)
0      */12          *            *                *                   /usr/bin/find


Oh so THATS what the extra * stands for LMAO... duhhh, I guess that makes sense...

And if I put something like

Code:
*/59 */2 * * * root /sbin/coldreboot

will that confuse the command or is there a "hierarchy" of what it takes first? I know there are different syntax to make it go on specific hours of specific days etc.... but I just wanna understand how Linux "sees" this command.....

Thanks!
 
That means it will run on the 59th minute of every 2nd hour. That is a hard example to understand. Let's say that instead you wrote
Code:
*/10 */2 * * *

this would run every 10 min of every 2nd hour. or put another way every 10 min at 14:00,, every 10 min at 16:00, every 10 min at 18:00 ...
 
That means it will run on the 59th minute of every 2nd hour. That is a hard example to understand. Let's say that instead you wrote
Code:
*/10 */2 * * *

this would run every 10 min of every 2nd hour. or put another way every 10 min at 14:00,, every 10 min at 16:00, every 10 min at 18:00 ...

Wow, ummm ok I didnt expect that, thats quite some micromanagement abilities....

So if I simply wanted to run something once every 2 hours, it would be
Code:
* */2 * * *
or do I need to put in like
Code:
*/59 */2 * * *
?

And if something once every 3 days,
Code:
* * */3 * *
or does that run every 3rd day of every month, like Mar 3, Apr 3, May 3, etc....?
 
Wow, ummm ok I didnt expect that, thats quite some micromanagement abilities....

So if I simply wanted to run something once every 2 hours, it would be
Code:
* */2 * * *
That would run every minute of every other hour
or do I need to put in like
Code:
*/59 */2 * * *
That would run on the 59th of every other hour. Anything over half really messes with the timing when using "/" because it is not a continual counter. For example in the minute column the biggest number you could have there is 59 as 60 would be an hour and would be written in the next column. Therefore every /59 would run at 0 and 59.

And if something once every 3 days,
Code:
* * */3 * *
or does that run every 3rd day of every month, like Mar 3, Apr 3, May 3, etc....?
Close,
Code:
0 0 */3 * *
Would run at midnight every 3 days

Code:
0 0 3 * *
Would run at midnight on the 3rd of every month

But to answer your first question to run something once every 2 hours
Code:
30 */2 * * *

which would be half past every other hour. Which is something that has caused me grief as I have wanted something to run every few hours but not specify at exactly which minute to have it run at. But then you get into random times and it get much more involved from there on.
 
Code:
0 0 */3 * *
Would run at midnight every 3 days

Code:
0 0 3 * *
Would run at midnight on the 3rd of every month

But to answer your first question to run something once every 2 hours
Code:
30 */2 * * *

which would be half past every other hour. Which is something that has caused me grief as I have wanted something to run every few hours but not specify at exactly which minute to have it run at. But then you get into random times and it get much more involved from there on.

Ok its starting to make sense but then again, I dont understand:

Code:
0 0 */3 * *
runs one time (midnight) every 3 days, i.e., once every 3 days
but then why not use
Code:
0 */2 * * *
to run something every 2 hours.... why even bother putting in a 30 since it seems like 0 means once by default?

I feel like
Code:
30 */2 * * *
should run twice every 2 hours, at :00 and at :30... and that
Code:
(31-59) */2 * * *
should run just once per hour. But you said even 59 will make it run at :00 and at :59, makes no sense there.....
 
I suggest just putting * * * */10 * be patient and test in practice how it works :p
 
Ok its starting to make sense but then again, I dont understand:

Code:
0 0 */3 * *
runs one time (midnight) every 3 days, i.e., once every 3 days

It does not mean once every 3 days, it means at the 0 minute of the 0 hour every 3 days.
but then why not use
Code:
0 */2 * * *
to run something every 2 hours.... why even bother putting in a 30 since it seems like 0 means once by default?
Sure that would work but not why you think, 30 was just a number i pulled out of the air. So by putting 30 it will run at the 30th minute of the hour. If you put 0 it will run at the 0th minute of the hour. If you are running multiple cron jobs, some times you are trying to space them out so it is necessary to specify the exact minute you want the job to run. You could put 7 as the first first number and have it run at 7 after.

To make it even more confusing you could write
Code:
4,15,32 * 6 * *
Which would run the job on the 4th, 15th and 32nd minute of every hour in June.

I feel like
Code:
30 */2 * * *
should run twice every 2 hours, at :00 and at :30
That would run on the 30th minute of every 2nd hour. To run twice every 2 hours you would need a "/" before the 30

Code:
/30 */2 * * *
... and that
Code:
(31-59) */2 * * *
should run just once per hour. But you said even 59 will make it run at :00 and at :59, makes no sense there.....
Not sure what you mean here.
If you wrote
Code:
31-59 */2 * * *
it would run every minute between and including 31-59. So 28 times.
The reason /59 will run twice in an hour is because the biggest number that the minute column understands is 59, therefore the only way to to execute that would be twice in one hour since it is unable 'to carry the 1'

Code:
*         *         *      *        *      command to be executed 
-         -         -     -       -
|         |         |     |       | 
|         |         |     |       +----- day of week (0 - 6) (Sunday=0)
|         |         |     +------- month (1 - 12)
|         |         +--------- day of month (1 - 31)
|         +----------- hour (0 - 23)
+------------- min (0 - 59)
Try http://cron.schlitt.info/ it will let you play with those definitions. I find it is the easiest way to understand and try out your theories. or google cron test for another option.
 
Try http://cron.schlitt.info/ it will let you play with those definitions. I find it is the easiest way to understand and try out your theories. or google cron test for another option.

Sweet! That tester rules... I think I am getting pretty much all of it now, just some syntax confusion but I think I'm good now.... thanks for being so thorough and patient... without this, its a bear to "test" out things, ie, i can set my cell phone timer for 2 hours and sit at my computer looking to see if it reboots right then, but I think anyone would agree thats a pretty ghetto way to test such an elegant command. :D
 
But........
That would run on the 30th minute of every 2nd hour. To run twice every 2 hours you would need a "/" before the 30
Code:
/30 */2 * * *
gives me an error when I plug it into that tester.

Also, this may be related, but then is it impossible to say, make something run every 45 minutes? Or every 35 minutes, etc.....?
 
But........

Code:
/30 */2 * * *
gives me an error when I plug it into that tester.

Also, this may be related, but then is it impossible to say, make something run every 45 minutes? Or every 35 minutes, etc.....?

You also need the * if you use the /.
 
Also, this may be related, but then is it impossible to say, make something run every 45 minutes? Or every 35 minutes, etc.....?

That's tricky. The way I do it, and maybe there is a better way, is you have to do some math and logic. So for every 45 min I would setup 3 different cron jobs as such

Code:
0,45  0-23/3 * * *
30    1-23/3 * * *
15    2-23/3 * * *
So the 0,1,2 says start the every 3 hours at different times. I'll explain it further if it doesn't make sense.
 
Back
Top