View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 10 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: crontab problems
PostPosted: Wed Apr 18, 2018 5:49 pm 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 11
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?


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Wed Apr 18, 2018 6:39 pm 
Offline
Joined: Thu Sep 27, 2007 5:44 pm
Posts: 459
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Thu Apr 19, 2018 6:00 am 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 11
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?


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Thu Apr 19, 2018 10:57 am 
Offline
Joined: Thu Sep 27, 2007 5:44 pm
Posts: 459
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Thu Apr 19, 2018 1:16 pm 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 11
Ok great, i will move this into crontab


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Fri Apr 20, 2018 5:09 am 
Offline
Joined: Tue Mar 27, 2018 12:02 pm
Posts: 11
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Fri Apr 20, 2018 6:57 am 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1096
Location: SC
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Fri Apr 20, 2018 11:38 am 
Offline
Joined: Thu Sep 27, 2007 5:44 pm
Posts: 459
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Fri Apr 20, 2018 1:45 pm 
Offline
Joined: Fri Jul 21, 2006 11:12 pm
Posts: 1096
Location: SC
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.


Top
 Profile  
 
 Post subject: Re: crontab problems
PostPosted: Fri Apr 20, 2018 3:58 pm 
Offline
Joined: Thu Sep 27, 2007 5:44 pm
Posts: 459
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.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu