Beancount getting started

stackoverflow indeed, i posted the same question there

Sorry, I didn’t see this comment. Of course if your machine is not online you cannot update de prices file! But
 normally, if your machine is off you don’t check beancount, isn’t it? :wink:
So, when you switch on again the machine will update all the days missing in the price.bean file.

I don’t see the problem. Surely I’m missing something


Well, if you are using Ubuntu, put the script in /etc/cron.daily/ or /etc/cron.hourly and without doing anything else your script will be executed every day, hour, etc. You don’t need anything else.

This is exactly what is not happening. this entry of mine above should send an email / make a log entry every full hour. the logfile (and my mailbox) only contains entries only from when the machine was running, but not from during the night when it was off. so it exactly misses what it is supposed to do :confused:

For bean-price to fetch prices it needs a price source, what I have are a couple of plugins that work with bean-price to fetch the prices from some places.

Ok i think there is a misunderstanding. let me start from the beginning.

I’d like to update my beancount asset prices daily. I know i can achieve this by making a cronjob. But if for some reasons I do not turn on my computer at the time specified in the cronjob, it will not execute.

For exactly this situation, fcron offers the bootrun opion. It forces jobs to execute on system startup if they were scheduled for during the last down time.

Imaging i specify a “unlucky” time of the day when my machine is guaranteed off, then the job would never run.

I could not yet get any effect out of using this option. Hence I ask if you know how to use this option.

Okkkk
 Now is clear.
I don’t know how to do what you want, sorry.

But what I know is that imagine I have in price.bean the prices for the 23rd, 24th and 25th of whatever month and I switch off the computer the 25th.

Now if I switch on the 31th, the crontab run the script the 31th and bean-price check all the data in your broker.bean file. Since the stocks are still there, haven’t been sold, the price is automatically updated for the 26th, 27th, 28th, 29th, 30th, and 31st


In any case I’m having everyday my computer on, so I cannot be 100% sure about that but I’m practically sure that works like that.

Regards.

uhh that i was not aware of, i thought bean-prices fetches only the prices of the current or specified date. hmm have to rearrange some thinking of mine :slight_smile: but thanks

It depends. Not all price plugins support fetching for a specific date. So for some you can only fetch the latest.

i am not yet aware that there are different plugins. i guess i’d find out more if i read through your code?

Yes, bean price is just the framework, see http://furius.ca/beancount/doc/prices

Thanks for the GLOBAL_QUOTE for Alphavantage! I was using the TIME_SERIES_DAILY which is great for getting historical data (maybe upgrade your plugin?) but some symbols where missing. Now thanks to your tip I am a happy daily price updater (into GNUCash so far, but hey the code is quite reusable).

@ cronjobs:
Can you help me with this: bean-price seems not to work via cron. in my (f)crontab there are two lines

0 * * * * bean-price --no-cache /home/pathTo/main.bean >>  /home/pathTo/testpricecron.bean
0 * * * * echo "$(date)"  >>  /home/pathTo/testpricecron.bean

which should (my intention) write down the price of my active assets and then the date every full hour. both commands work flawlessly from command line. but via cronjob, the asset prices won’t show up in the log. do you have any idea why?

[edit]
the logfile looks like

Mon Apr 27 21:00:00 CEST 2020
Mon Apr 27 22:00:00 CEST 2020
Mon Apr 27 23:00:00 CEST 2020
Tue Apr 28 08:00:00 CEST 2020
Tue Apr 28 09:00:00 CEST 2020
Tue Apr 28 10:00:00 CEST 2020

and copy pasting the line with bean-price to the command line perfectly does its job by appending to the logfile:

~$ bean-price --no-cache /home/pathTo/main.bean >>  /home/pathTo/testpricecron.bean
2020-04-28 price EUR                                  1.06 CHF
2020-04-28 price USD                                  0.98 CHF
2020-04-27 price VTI                                144.14 USD

Does it do anything Beancount-related? One thing to explore would be your PATH and Python env variables. You can set them explicitly if needed at the beginning of a Bash script and then schedule that script on Cron.

Or is the problem something else?

Nugget, as @Ed_Waadt pointed is nothing related to beancount, is linux stuff. In the cron you must put the complete path to the commands because cron is a special user that hasn’t any path. There are other systems to add the path to the cron but the easier is putting the complete command in the cron.

So, if bean-price is i.e. in /usr/local/python/ you must put

0 * * * * /usr/local/python/bean-price /path/main.bean etc. etc.

You can check where bean-price is with the command

# whereis bean-price

Another free advise is not using 0 * * * * . Is better do the thing out of the 0 minutes because at 0 there are several processes in the machine that are executed, logrotate, save files, etc. Is always better do the execution out the singular dates or hours.

Regards.

2 Likes

wow, you nailed it again. That exactly fixes it! Thanks!
Tbh, i would not have guessed that from Ed_Waadt’s answer. but now it makes sense, of course!

1 Like

Because I’m clearly not a good teacher. I identified the issue but was unable to convey the message in an inteligible manner. So thumbs up, @Tino !

1 Like

@nugget, since you are really nice :stuck_out_tongue_winking_eye:, I’m going to give you another tip for the next time you have problems.
The cron jobs are all logged by default to /var/log/syslog and that’s the first place to check if things are not running as you expect.

If you check in the file /var/log/syslog the date/times you were running the old command you did in crontab without the path you will find something like: (not exact, depends of your system)

Apr 29 17:17:01 ubuntu CRON[7037]: (root) CMD (command bean-price not found)

Regards.

1 Like

thanks for the tip!
however i don’t have a syslog file or folder at this place:

but yes makes sense if there is some logfile to check it :+1:

Yep
 I forgot you are using Docker. The docker for Ubuntu doesn’t have the syslog installed by default. Try to do :

apt-get -y install rsyslog

If works, you’ll have the syslog installed and the file will apear in /var/log/

To test, run:

logger "Test Log"

You should find an entry in the syslog.

Regards.