Ask / Submit
1

curl in crontab: Empty output

asked 2018-02-17 11:42:27 +0200

wickedsp1d3r gravatar image

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 flag offensive close delete

Comments

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.

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

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

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

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

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

2 Answers

Sort by » oldest newest most voted
2

answered 2018-02-17 17:03:32 +0200

adekker gravatar image

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.

edit flag offensive delete publish link more

Comments

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.

juiceme ( 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)

    39 * * * * /bin/su - nemo -c "/usr/bin/curl -sSkL https://rawgit.com > /home/nemo/Downloads/test" -rw-r--r-- 1 nemo nemo 4650 2018-02-18 20:39 /home/nemo/Downloads/test

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).

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

@adekker it's a deal :)

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.

juiceme ( 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... :(

juiceme ( 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.

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

answered 2018-02-17 13:39:10 +0200

juiceme gravatar image

updated 2018-02-21 18:04:43 +0200

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;

https://together.jolla.com/question/16434/cronjob-on-sailfish/?answer=179698#post-id-179698

edit flag offensive delete publish link more

Comments

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

wickedsp1d3r ( 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.

juiceme ( 2018-02-18 13:29:49 +0200 )edit
Login/Signup to Answer

Question tools

Follow
2 followers

Stats

Asked: 2018-02-17 11:42:27 +0200

Seen: 291 times

Last updated: Feb 21 '18