LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Crontab - Detailed Questions (https://www.linuxquestions.org/questions/debian-26/crontab-detailed-questions-4175602232/)

halek37 03-20-2017 06:30 PM

Crontab - Detailed Questions
 
With all the help from this group I now have Crontab working, but have a few more detailed questions.

1. is there any limit to how many individual Crontabs can be entered at once?
Here is a 2 line example
Code:

30 8 * * * sh vida
30 9 * * * sh vidb

I would like to do 4 different crontabs a day for 5 days 20 Lines total

2. If those 20 lines are entered and then the Rpi is shut down overnight will all the data be retained. Or would it be required that the next 16 would have to be reentered after a reboot the following morning.

I have found that if i use a script as below that the FireFox line will open without any problem, apparently because the OMXplayer closes at the end of the video. However if the Firefox is run before the OMXplayer then the the FireFox must be shutdown before the OMXplayer can start.

Code:

#!/bin/bash
export DISPLAY=:0 && /usr/bin/omxplayer -o hdmi '/home/pi/Videos/Tue Compact.mp4'
 echo $(date) >> /home/pi/ek.log
firefox

3. Is there a way to send a shutdown from Crontab? Ctrl+C works in terminal.Or is there a workaround?

4. I have tried to get the email sent to my address at home. I added the following as the first line below the shebang in my script.
____ MAILTO=xyz@bellsouth.net
But I did not get any email.
Otherwise the script would be the same as in the second code box without the firefox

Thanks!

dijetlo 03-21-2017 10:16 AM

Quote:

1. is there any limit to how many individual Crontabs can be entered at once? ... I would like to do 4 different crontabs a day for 5 days 20 Lines total
Cron a service, crontab it's configuration file so no, though you may be eating up a lot of processor capacity running the individual services that cron triggers, the service itself isn't burdened by them.
Quote:

If those 20 lines are entered and then the Rpi is shut down overnight will all the data be retained
The crontab will remain persistent and the service will trigger the events listed therein. Any data gathered by those events is another question, however.
Quote:

3. Is there a way to send a shutdown from Crontab?
You could trigger a script that locates the PID (since you know the application name) and sends it a kill signal or a dbus trigger (a slightly different script instantiated by cron via the crontab).
Quote:

4. I have tried to get the email sent to my address at home. I added the following as the first line below the shebang in my script.
You'd probably have better luck sending the message to a local node, rather than your internet mail account. There can be a lot of reasons mail doesn't get passed along through the MTA/MTU infrastructure, first among them being none of them can resolve the originating domain (aka Spam).
Quote:

With all the help from this group I now have Crontab working,
:thumbsup: Outstanding!

michaelk 03-21-2017 11:01 AM

crontab is a program used to maintain crontab files. No limit on how many you can enter. Depending on what version of cron is running there could be a limit on the total number of cron jobs but 20 is not a problem. No problem with shutting down the Pi but jobs will not automatically run if you start it back up after a scheduled time.

Many ways to kill a process. You can use pkill, killall, pgrep commands You can use pidof to find the PID of a running process.

halek37 03-21-2017 11:16 AM

Quote:

Originally Posted by halek37 (Post 5686171)
With all the help from this group I now have Crontab working, but have a few more detailed questions.

1. is there any limit to how many individual Crontabs can be entered at once?
Here is a 2 line example
Code:

30 8 * * * sh vida
30 9 * * * sh vidb

I would like to do 4 different crontabs a day for 5 days 20 Lines total

2. If those 20 lines are entered and then the Rpi is shut down overnight will all the data be retained. Or would it be required that the next 16 would have to be reentered after a reboot the following morning.

I have found that if i use a script as below that the FireFox line will open without any problem, apparently because the OMXplayer closes at the end of the video. However if the Firefox is run before the OMXplayer then the the FireFox must be shutdown before the OMXplayer can start.

Code:

#!/bin/bash
export DISPLAY=:0 && /usr/bin/omxplayer -o hdmi '/home/pi/Videos/Tue Compact.mp4'
 echo $(date) >> /home/pi/ek.log
firefox

3. Is there a way to send a shutdown from Crontab? Ctrl+C works in terminal.Or is there a workaround?

4. I have tried to get the email sent to my address at home. I added the following as the first line below the shebang in my script.
____ MAILTO=xyz@bellsouth.net
But I did not get any email.
Otherwise the script would be the same as in the second code box without the firefox

Thanks!

michaelk 03-21-2017 11:22 AM

Why did you copy your original post? Did you read the replies?

What do you not understand?

halek37 03-21-2017 11:51 AM

Sorry
 
Quote:

Originally Posted by michaelk (Post 5686426)
Why did you copy your original post? Did you read the replies?

What do you not understand?

Sorry I did not intend to copy my original Post.

I did read them all but was trying to understand How to use the Quote Box.
Thanks again, I think I understand what was sent, with a small exception that I was going to experiment with.

If I use the killall in a script in crontab to kill the firefox before running the next omxplayer. Would that kill the crontab also?

michaelk 03-21-2017 12:20 PM

No it will not.

dijetlo 03-21-2017 02:27 PM

If you prefaced your omxplayer script with a line like
(treat the following as pseudocode)
kill $(ps aux | grep [f]irefox | awk '{print $2}') 9 && sleep 10

and if you only have a single instance of firefox running at that time, it should zap it prior to omxplayer starting up

Quote:

Sorry I did not intend to copy my original Post.
no worries :)

Hope that helps

michaelk 03-21-2017 02:37 PM

Code:

$(ps aux | grep [f]irefox | awk '{print $2}')
You can simply a bit...
Code:

$(pidof firefox)

dijetlo 03-21-2017 02:43 PM

:doh:

Doesn't work on Unix systems and therefor, not Posix compliant ? ( I don't have a Solaris node handy at the moment, I'm just guessing here...)

:hattip:

michaelk 03-21-2017 02:57 PM

pidof is actually a link to killall5. It's been a long time since I've played with Unix...

halek37 03-21-2017 03:46 PM

Everytime I feel like I see the light at the end of the tunnel I find that it really is just a hole before starting the next tunnel. but THANK You all for your help!

I will include 2 scripts That I ran with crontab on 2 lines a minute apart.
The first is the script that I setup to run my video and when it was finished open firefox. But I found that that needed a way to shut firefox down.
My solution one
Code:

#vidb To play video from a script
#
#!/bin/bash
export DISPLAY=:0 && /usr/bin/omxplayer -o hdmi '/home/pi/Videos/Tue Compact.mp4'
 echo 'Ran vidb' >>  /home/pi/ek.log
 echo $(date) >> /home/pi/ek.log

firefox

That worked just great, firefox went away and my video played but when it finished firefox opened again. So I tried addind the second killall, but had no effect.
Code:

#vidd3 To play video from a script with killall
#!/bin/bash
killall -eq firefox
export DISPLAY=:0 && /usr/bin/omxplayer -o hdmi '/home/pi/Videos/Tue Compact.mp4'
 echo 'ran vidd3' >>  /home/pi/ek.log
 echo $(date) >> /home/pi/ek.log
killall -eq firefox

I have not tried your latest sugestions yet.
Is the problem somehow related to the display function?


All times are GMT -5. The time now is 04:37 AM.