biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Crontab Midori command

Wed Aug 22, 2012 8:17 pm

Dear Guys,
Here I got into a weird situation:
I opened a html file using midori browser, and since I use a cron job to modify the html in each 5 minutes. I need to refresh the browser each five minutes just to make sure that it is displaying the latest html file.
there is a command

Code: Select all

midori -e Reload

works if I type in the command line, but what is weird, it doesn't work if I put that in the crontab. I have included the path of midori in the crontab(basically which crontab returned usr/bin/midori) , I don't know why it doesn't work.
To fix it, I try to open a new window each five minute and kill the previous one.
Same,

Code: Select all

Midori /root/filename.html
only work if I type them in by hand and still doesn't work in the crontab.
Here I am wondering does that mean all the midori commands doesn't work in the cron??
If not, how to do that? Any help is appreciated!

User avatar
joan
Posts: 16259
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Crontab Midori command

Wed Aug 22, 2012 8:25 pm

Could you post the output of

sudo crontab -l

and

crontab -l

W. H. Heydt
Posts: 16363
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Crontab Midori command

Wed Aug 22, 2012 9:05 pm

Does starting a shell script with cron that contains the initial start of Midori and loop to refresh it work?

(I have an interest in getting something like this working myself and will be watching--and testing--the answers....)

biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Re: Crontab Midori command

Wed Aug 22, 2012 9:11 pm

Below is crontab -l
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * mkdir /CRONisRunning
* * * * * /createfolder.sh
*/5 * * * * /cronbash.sh
* * * * * /usr/bin/midori -a http://www.google.com
note: mkdir /CRONisRunnng to make sure cron is running (I also use pgrep cron to do that)
all the commands that I want is in the cronbash.sh
Below is the cronbash.sh content

Code: Select all

#! /bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
mkdir /OK
/usr/bin/midori -e Reload
Rscript -e "knitr::knit2html('filename.Rmd')"
note: mkdir to make sure this script has been executed
Rscript is a command to convert Rmd file to a html file, this is the command that keep the html
changing all the time.

PS. I can see from the ps aux that all the script are running and I can even figure out that the command midori -a google.com did run, but I just can't see a browser window pop up waiting for a long time. I heard from some people there are some issues around export to display...etc. I think that might be the problem or....commands that brought up GUI will not run easily in the crontab if you don't do any work.
Also, I want to run crontab at booting and type in rcconf, I can see that the cron is checked but everytime i boot up my raspberry pi, Pgrep cron return nothing.
Thanks for any help and I think it is a pretty challenging work figured everything out. Any help appreciated.

biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Re: Crontab Midori command

Wed Aug 22, 2012 9:14 pm

W. H. Heydt wrote:Does starting a shell script with cron that contains the initial start of Midori and loop to refresh it work?

(I have an interest in getting something like this working myself and will be watching--and testing--the answers....)
Thanks for your attention Hydit, I am not quite sure about that, but I know just

Code: Select all

/usr/bin/midori -a https://google.com
doesn't work if you simply put that in the crontab.

Let me know when you make any progress.

biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Re: Crontab Midori command

Wed Aug 22, 2012 9:56 pm

Mission Completed....

cited from UbuntuForums: henriquemaia
crontab: How to run GUI programs with cron
See Original Link http://ubuntuforums.org/archive/index.php/t-185993.html
-----------------------------------------------------------------------------------------------------------
This is an updated Thread from 5.10. It works on 6.06.


First of all, please refer to this howto (http://ubuntuforums.org/showthread.php? ... light=cron) to learn more about crontab.


My motivation to find this out was because there are several radio shows I really like and I was always missing them. As such, I needed something to make amarok play the chosen radio station at specific times. Probably this could be achieved through a more elegant solution, but what is explained here works great. Also, I knew that by learning how to do this, I could use it for many other things.

To accomplish this, you have to edit your crontab:

crontab -eyou can also use a nicer GUI tool to edit crontab, like gnome-schedule or KCron (both available on the repositories).

If you use a GUI tool, please adapt the instructions accordingly. I will explain this using as basis the default crontab editor.

To run a GUI command on cron, you'll have to tell cron what display the program should use. For that you use:

export DISPLAY=:0 The ':0' is the default. If you like the program to run on other display, please change the number accordingly (e.g. :1, :2, etc).

So, you add to what is explained here (http://ubuntuforums.org/showthread.php? ... light=cron):

01 04 * * * /usr/bin/somedirectory/somecommandthe export variable, like this:

01 04 * * * export DISPLAY=:0 && /usr/bin/somedirectory/somecommandYou can omit the full path to the application bin. For amarok, you just need to use the 'amarok' command. Works fine both ways.

So, in my case, as I want amarok to play Antena2 (Portuguese classical radio station) at a specific time, I use:

30 16 * * 7 export DISPLAY=:0 && amarok mms://rdp.oninet.pt/antena2 This will make amarok start the Antena2 url every Sunday, at 16:30. But I want also to shut up amarok after the show is finished. So, I use:

0 17 * * 7 export DISPLAY=:0 && amarok -s
This will shut up amarok at 17:00 every Sunday.

(Just a side note - to make amarok play mms urls, you have to set it to use xine engine)

You can use this export trick to the limits of your imagination with every kind of application you want.

Another example that occurs to me is when you neet to use an application for a certain period of time, from 3AM to 9AM, for exemple.

0 3 * * * export DISPLAY=:0 && your_favorite_applicationthat will start your_favorite_application (change this to the command that runs the application you desire) everyday at 3AM. To shut it down, I use:

0 9 * * * killall your_favorite_applicationThis will shut it down at 9AM.

Hope this helps some of you.

If you have more ideas how to use this trick (or how to improve this HowTo), please share with us in this thread.

W. H. Heydt
Posts: 16363
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Crontab Midori command

Thu Aug 23, 2012 10:17 pm

I haven't tried it from crontab yet, but a shell script that launches the browser, puts it in background, and then does an infinite loop of waiting one minute and the issuing a reload works.

biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Re: Crontab Midori command

Fri Aug 24, 2012 4:50 am

I am wondering can u share your script code with us? Interested how u put in background TTY?

W. H. Heydt
Posts: 16363
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Crontab Midori command

Fri Aug 24, 2012 6:04 am

biwa7636 wrote:I am wondering can u share your script code with us? Interested how u put in background TTY?
This brings up a twitter feed and then refreshes it...

Code: Select all

pi@rpi2dev ~ $ cat autotwit
#!/bin/bash

# autotwit
#
# usage: autotwit <twitterID>
#
# Starts Midori browser and reloads it
# once per minute.
#
# Please send any modifications back to [email protected]
#
# W. H. Heydt, 23 August 2012

# Echo source file.

echo Twitter ID: $1

# Clear previous session (to prevent opening extra tab)

rm -f ~/.config/midori/session.xbel

# Start Midori, run in background

midori http://twitter.com/$1 &

# set infinite loop.

while [ TRUE ]; do

# Wait 1 minute, then reload page.

   sleep 60

   midori --execute ReloadUncached

done
pi@rpi2dev ~ $
Hope that helps...

biwa7636
Posts: 24
Joined: Mon Aug 06, 2012 2:23 pm

Re: Crontab Midori command

Fri Aug 24, 2012 4:08 pm

That is a good idea to run a script at booting to make that happen. Thank a lot.
Right now, I try to build a dashboard to display different html files in a same folder(The html files keep updating themselves).
So I need to figure out these tasks:
1. Display html full screen at booting not in the back, in the front. (I just figured out using DISPLAY=0:)
2. Reopen different htmls at a specific time interval and the process should be made smooth like a slideshow. (You can use iceweasel tab-slideshow plugin in to do that, but it is a little heavy for our Pi and you can only switch between different tabs instead of reopening each time, the content on each page can't be updated)
3. No rolling codes while booting instead, I prefer a fancy picture.

Problem 2 is the core part of my 'fancy dashboard' and I think I might do it using bash as you mentioned.
the frame might look like below

Code: Select all

export display=0: && midori open a list of html files in a same window different tab -e Fullscreen
while(1)
{
     if( htmls list been changed)
     { open added html && remove deleted tab}
     sleep(10)
     change the tab to the next one.
}
Well an easy dashboard can be done long time ago, one page static dashboard. while, I am pretty enthusiastic whether we can use our Pi to build a perfect commercial level dashboard.
Go geeks!

Return to “General discussion”