LinHES Forums
http://forums.linhes.org/

crontab problems
http://forums.linhes.org/viewtopic.php?f=5&t=24752
Page 1 of 1

Author:  caymann [ Wed Apr 18, 2018 5:49 pm ]
Post subject:  crontab problems

I logged in as root
crontab -e

i added the following (run myscript.sh at 2.10AM every morning)

10 02 00 * * /usr/bin/myscript.sh >/dev/null 2>&1

I know that i can run myscript.sh and it would run fine.

Unfortunately i am not sure if this is actually executing under cron?

Any sugestions?

Author:  knappster [ Wed Apr 18, 2018 6:39 pm ]
Post subject:  Re: crontab problems

Caymann

I just have a moment to post but I think you are calling it to run on the 0 day of the month so it will never run:
https://en.m.wikipedia.org/wiki/Cron

edit: further to my original post, your crontab entry appears to be as follows:
10 02 00 * * /usr/bin/myscript.sh >/dev/null 2>&1

Broken down:
Minute: 10
Hour: 02 (2 am)
Day of Month: 00 (none)
Month: * (all)
Day of week: * (all)
Command: /usr/bin/myscript.sh >/dev/null 2>&1

What you need to run it at 2:10 am each day, is:
10 2 * * * /usr/bin/myscript.sh >/dev/null 2>&1

You could consider writing to a file in your script if you need to be able to check if it ran, because I am unaware of any logs by cron.

Author:  caymann [ Thu Apr 19, 2018 6:00 am ]
Post subject:  Re: crontab problems

Ahh, that would explain it. I will fix that and see what happens.

Upon reading the forum, i learned that LinHES uses dcron instead of cron.
Is that true?

I see directories like /etc/cron.daily , /etc/cron.weekly ...
Each of these directories has several bash scripts running
For now i put my script in the /etc/cron.weekly directory
Not sure which day of the week this runs and at what time?

Will that work?

Author:  knappster [ Thu Apr 19, 2018 10:57 am ]
Post subject:  Re: crontab problems

I wouldn't touch the /etc/cron.* directories personally, but that's just because they are used for system tasks and I didn't want to impact anything. I don't know how to determine when the weekly stuff will run. I kind of suspect it will look at the last time they ran and if it has been a week or longer, it will run again in order to work more gracefully with system shutdowns (the computer may be powered off when it is scheduled to run). Don't take me at my word on this because I am merely speculating.

If your computer is going to be on at 2:10 am every day, I would set it up as you were going to initially with the updated settings I provided. I would also move that script into the home directory because if you update to a new version of LinHES, it could get wiped out in the /usr/bin/ directory.

Author:  caymann [ Thu Apr 19, 2018 1:16 pm ]
Post subject:  Re: crontab problems

Ok great, i will move this into crontab

Author:  caymann [ Fri Apr 20, 2018 5:09 am ]
Post subject:  Re: crontab problems

Sorry, but crontab is not doing it.

I logged in as root.
I tried to run this at 6.45AM for as quick test

[root@mythtv ~]# crontab -e

This is what the contents of crontab looks like:-

# root crontab
# DO NOT EDIT THIS FILE MANUALLY! USE crontab -e INSTEAD

# man 1 crontab for acceptable formats:
# <minute> <hour> <day> <month> <dow> <tags and command>
# <@freq> <tags and command>

# SYSTEM DAILY/WEEKLY/... FOLDERS
@hourly ID=sys-hourly /usr/bin/run-cron /etc/cron.hourly
@daily ID=sys-daily /usr/bin/run-cron /etc/cron.daily
@weekly ID=sys-weekly /usr/bin/run-cron /etc/cron.weekly
@monthly ID=sys-monthly /usr/bin/run-cron /etc/cron.monthly
0,10,20,30,40,50 * * * * /usr/bin/run-cron /etc/cron.tenminutes
45 06 * * * /usr/bin/mycode.sh >/dev/null 2>&1


I have no idea how to check if crontab actually ran.
When i look at the output of the mycode.sh, it shows nothing
When i ram mycode.sh, i saw output.

Author:  brfransen [ Fri Apr 20, 2018 6:57 am ]
Post subject:  Re: crontab problems

The /etc/cron.* will work great for this. Just drop your file in the directory you want for the frequency you want. knappster is correct they will run by looking at the last time they were executed and if it is greater than it will run. So if you need it to run at a specific time then you need to create your own cron job.

You are not getting output because you are redirecting std in/out to /dev/null. Redirect to a file to see the output.

Author:  knappster [ Fri Apr 20, 2018 11:38 am ]
Post subject:  Re: crontab problems

One last thing I wanted to point out was that by setting it up using
Code:
crontab -e
as root user, it will run the script as root. If you don't need root privileges, then it would be "safer" to set it up using crontab as the mythtv user. Just don't forget to give the proper file permissions to the user you are running as.

I am not certain which user the /etc/cron.* scripts run as.

Author:  brfransen [ Fri Apr 20, 2018 1:45 pm ]
Post subject:  Re: crontab problems

knappster wrote:
I am not certain which user the /etc/cron.* scripts run as.
Root. Look at the root crontab and you can see how the cron.tenminutes and others are implemented.

Author:  knappster [ Fri Apr 20, 2018 3:58 pm ]
Post subject:  Re: crontab problems

brfransen wrote:
knappster wrote:
I am not certain which user the /etc/cron.* scripts run as.
Root. Look at the root crontab and you can see how the cron.tenminutes and others are implemented.


Oh right. caymann printed his root crontab output which demonstrated this. Duh.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/