curl in crontab: Empty output

I try to use curl in crontab. For testing purposes I defined a job like this:

*/5 * * * * /usr/bin/curl -sSkL https://rawgit.com > /home/nemo/Downloads/test


The output file is empty. At first I thought the reason is HTTPS, but seems like it is not the cause.

When I run the command manually, it works as it should. Does anyone know why?

edit retag close delete

I'm not familiar with crontab, but tried your line of code anyway and I got -bash: */5: No such file.

So I tried again but without */5**** and then the test file was populated with data.

( 2018-02-17 12:52:32 +0200 )edit
2

@Edz it's a crontab line and not a bash command :) :)

( 2018-02-17 13:40:27 +0200 )edit

lol, thanks, I did say I'm not familiar with crontab! :P

( 2018-02-17 14:07:05 +0200 )edit

Sort by » oldest newest most voted

Your issue here has no relation with sleep/wake states. You cannot resolve any domain, because you are not allowed to do so. So using its IP address (104.18.63.176), which requires no resolving, works.

The root cause is most probably that you do not have secondary groups at your disposal when running from cron. This can be avoided by using the root cron (and then /bin/su - nemo -c "your command")

There are indeed differences in standard nemo permissions between the Jolla 1 and Xperia X, so your command would have worked on a Jolla 1.

more

I am so sorry to tell you you have it very very wrong.

It does not work regardless of whether you use a DMS name ot IP address.

( 2018-02-18 13:28:07 +0200 )edit
1

Based on IP it indeed fails on connection errors. I must have used a wrong testcase for this yesterday.

This doesn't change the theory (see earlier post) though, it only adds that using ip is also a nogo.

My testcases:

1. nemo https

28 * * * * /usr/bin/curl -sSkL https://rawgit.com > /home/nemo/Downloads/test 2>/tmp/error.txt -rw-r--r-- 1 nemo nemo 0 Feb 18 20:28 test error.txt: curl: (6) Could not resolve host: rawgit.com

2. nemo http

31 * * * * /usr/bin/curl -sSkL http://rawgit.com > /home/nemo/Downloads/test 2>/tmp/error.txt -rw-r--r-- 1 nemo nemo 0 Feb 18 20:31 test error.txt: curl: (6) Could not resolve host: rawgit.com

3. nemo ip

37 * * * * /usr/bin/curl -sSkL 104.18.63.176 > /home/nemo/Downloads/test 2>/tmp/error.txt -rw-r--r-- 1 nemo nemo 0 Feb 18 20:31 test error.txt: curl: (7) Couldn't connect to server

4. nemo via root (https)

testcase 4 works consistent (see earlier post why I think this works).

Now if you are so convinced of your deep sleep theory (and I am "very, very wrong" as you say), please provide some logging/testcases that supports your theory.

If you can't, be so kind and remove your downvote (and of course you will get my upvote if your theory proofs to be correct).

( 2018-02-18 22:18:55 +0200 )edit

why I think it is related to sleeping is because ip counters showed no traffic whatsoever when I invoked ping to 8.8.8.8 and that sure should have triggered at least outbound packet counter...

I'll try it in roots crontab and report the results.

( 2018-02-18 22:41:49 +0200 )edit
1

I will have to eat the humble pie... @adekker you are absolutely correct there. When running from cron I only have the "nemo" group and no secondaries at all, damn!

Now what led me astray is that even in roots crontab when I pinged a host I got no reaction at all; hence I was so sure it was an issue of networking rather than priviliges....

Now how to correct that? Of course I can do all network-related tasks from roots crontab but that feels kinda kludgy to me, I'd like to be able to rsync from nemos crontab... :(

( 2018-02-20 22:48:02 +0200 )edit

Using the root crontab to start a nemo process is a bit kludgy, but I am not aware of another clean solution.

( 2018-02-20 23:23:49 +0200 )edit

What's your device? If it is XperiaX then unfortunately it does not work that way as when the device is sleeping and cron wakes it up for some reason the network stack does not wake up :(

I noticed this as I use cron to backup my device with rsync during the night. With Jolla sbj1 it worked always, but with my XperiaX it doesnt.

I suppose the way to do it would be cron to wake up networking with a dbus message to ofono or network magager? It does not matter whether you have a wlan or LTE configured, network cannot be reached with either when the device is woken up by cron...

---------- edit ----------

Now I have been totally humiliated and will have to retreat in the corner in shame :(

The problem is indeed not sleep states as I so confidently assumed but the fact that nemo user does not have secondary groups when invoked from crontab... damn!

---------- edit ----------

The issue has been now fixed. See the posting in "cronjob-on-sailfish" thread;

more

Yes, I am using Xperia X. Do you know are there any plans to fix this issue in the future?

( 2018-02-17 15:48:15 +0200 )edit

I do not know whether it is a priority issue to fix. Apparently not many use cron to access network; in most use cases the UI is up and device fully woken when an application needs network access.

( 2018-02-18 13:29:49 +0200 )edit