Root crontab not running
Solution 1
I have three solution suggestions for you.
Invoke the crontab with
crontab -e -u root
Make sure that you have an empty line at the end of the cronjob file, meaning that every line ends with a newline.
You might need to redirect the output to devnull:
shutdown -r now > /dev/null
Here are two helpful webpages for cronjobs:
You can also handle the cronjobs neatly with webmin.
Other than that, you have at least two more ways for restarting your computer at midnight.
One is to run the shutdown command as a script automatically at login but with specific time as a parameter instead of "now":
shutdown -r 00:00
However, this will yield a broadcast message of upcoming shutdown at every login (might not be a bad thing at all). Well you can also make this be run at boot time by adding the script in init.d, still yielding the message, though.
Another is to use at
command:
at 0am
Enter command shutdown -r now
and save it with ctrl+d or do a script for the command and do:
at -f restart_script.sh 0am
Hope these help you to get the result you wanted.
Solution 2
System Cron jobs are listed in /etc/crontab file. Therefore editing this file directly will help you out to run the reboot command as root.
therefore,
$ sudo vi /etc/crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
23 20 * * * root shutdown -r now
make sure you check the Cron log file after editing the crontab as it will let you know if the cron was installed successfully.
I have tested it and it worked for me. Restarted my system at 8:23 PM
Good LUCK!
Related videos on Youtube
Wouter Nuijten
Updated on September 18, 2022Comments
-
Wouter Nuijten over 1 year
I'm building a CNN with Keras that predicts the coordinates of 13 keypoints in every image. The images I have vary in input dimension so my input layer shape is (None, None, 3). I am using Inception Modules so I am using the Functional API. Now, while coding the last layers for my model, I encountered a problem. As far as I know, my output layer wil be a Dense(26) layer, since I will encode the x and y coordinates as a vector. I have trouble connecting the output layer with the preceeding Convolutional layers (because of tensor dimensions)
x = Input(None, None, 3) stage_1 = Conv2D(26, (1, 1))(x) stage_1 = Dropout(0.3)(stage_1) stage_2 = Conv2D(512, (1, 1))(x) stage_2 = Dropout(0.3)(stage_2) stage_2 = Activation('relu')(stage_2) x = concatenate([stage_1, stage_2]) x = Lambda(lambda i: K.batch_flatten(i))(x) outputs = Dense(26)(x)
I tried including a Flatten Layer (but it is not compatible with arbitrary input shapes) and I've tried using K.batch_flatten() in a Lambda layer (which also did not work.) My question is: Is there a different way to get an output layer in a similar shape ((13,2) would also be fine, I just only found models online where the output layer is a Dense layer)? I also tried GlobalAveragePooling2d(), but this greatly decreased the accuracy of the model. Also, using a function to find the output shape did not work, see below
stage_1 = Conv2D(26, (1, 1))(x) stage_1 = Dropout(0.3)(stage_1) stage_2 = Conv2D(512, (1, 1))(x) stage_2 = Dropout(0.3)(stage_2) stage_2 = Activation('relu')(stage_2) x = concatenate([stage_1, stage_2]) def output_shape_batch(tensor_shape): print(tensor_shape) return (batch_size, tensor_shape[1] * tensor_shape[2] * tensor_shape[3]) x = Lambda(lambda i: K.batch_flatten(i), output_shape=output_shape_batch)(x) outputs = Dense(26)(x)
I expect the model to compile, but get TypeErrors The error is: TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
-
terdon over 9 yearsJust to make sure, you are closing the crontab after editing it, right? Also, how did you "run as root"? What is the output of
sudo crontab -l | grep -v '#'
? -
muru over 9 yearsWhy is this tagged debian? If this is about Debian and not Ubuntu, please ask on Unix & Linux.
-
Atomiklan over 9 yearsBecause debian is at the core of Ubuntu I believe.
-
-
Ahti Komu over 9 yearsNot true! Cron does not use 12 hour time format and the format is always mm hh DD MM WD.
-
Atomiklan over 9 yearsThe solution was to output to dev null. I wonder why?
-
Atomiklan over 9 yearsPlease read the whole post next time.
-
Ahti Komu over 9 yearsIt is because cron job has its own environment which does not have such a standard input/output system you'd expect and the process fails because it is trying to stream messages into a missing output pipe. Cron job is actually a lot different thing compared to running some command in terminal as any user. Glad to hear that you got it working after all.