Run from crontab
When running from crontab, I fail having faup to works as expected
I have this test script that use 2 ways to call faup (with full path)
#!/bin/bash -x
echo "----Start"
echo ""
echo "-- 1 --"
echo "www.github.com" | /bin/faup
echo $?
echo ""
echo "-- 2 --"
/bin/faup www.github.com
echo $?
echo ""
echo "----End"
When running not from cron, i have expected results:
+ echo ----Start
----Start
+ echo ''
+ echo '-- 1 --'
-- 1 --
+ echo www.github.com
+ /bin/faup
,,www,github.com,github,www.github.com,com,,,,,mozilla_tld
+ echo 0
0
+ echo ''
+ echo '-- 2 --'
-- 2 --
+ /bin/faup www.github.com
,,www,github.com,github,www.github.com,com,,,,,mozilla_tld
+ echo 0
0
+ echo ''
+ echo ----End
----End
When this script is called from crontab, the first command works fine, but the 2nd command does not create output
* 12 * * * /aaa/toto.sh > /tmp/tototo
----Start
-- 1 --
,,www,github.com,github,www.github.com,com,,,,,mozilla_tld
0
-- 2 --
0
----End
+ echo ----Start
+ echo ''
+ echo '-- 1 --'
+ echo www.github.com
+ /bin/faup
+ echo 0
+ echo ''
+ echo '-- 2 --'
+ /bin/faup www.github.com
+ echo 0
+ echo ''
+ echo ----End
/bin/faup -v
faup v1.6
FAUP_DATA_DIR=/usr/local/share/faup/
TLD file being used:/usr/local/share/faup/mozilla.tlds
I should admit I'm quite confused on why the first command works, but not the other one, only when running from cron. I tried to also change the env variables to match those when run from my user.. but no luck...
I tried on 2 different systems. Does someone reproduce same issue ? And/or have some clue on what I'm possibly doing wrong ?
Thank's
"cat" workaround has not bad performances, so will use that until I get a better understanding on my issue (may be interactive/non interactive session ? )
time faup -f domain_without_tld top-1m.csv > toto
real 0m3.602s
time cat top-1m.csv | faup -f domain_without_tld > toto
real 0m3.761s
thanks for reporting this, I try to make it as easy as possible, so I would expect what you do in the first place should work. If there is a good reason for this not to work, I would rather have a warning or something I can point out in the documentation.
I will see if I can reproduce and how to fix, so leaving this open until it gets resolved. Glad you have found a workout in between.
Thx, happy to help debugging if necessary.
I think the problem is https://github.com/stricaud/faup/blob/b65a4d816b008d715f4394cf2ccac474c1710350/src/tools/faup.c#L437. It will be false if running from cron so you end up at https://github.com/stricaud/faup/blob/b65a4d816b008d715f4394cf2ccac474c1710350/src/tools/faup.c#L469 which only accepts input from stdin.
I assume the fix would be to check for the presence of arguments, rather than a tty, to decide where to read input from, ala perl's <> operator.
(I haven't tested the above - just conjecture)
Thank's for the investigation 👍
Agreed, I will check this to implement the fix. I am able to reproduce this, so it should be quick. Thank you so much @andrew-stevenson-sociomantic