ack outputs nothing using crontab in linux

22 views
Skip to first unread message

Zhilong Jia

unread,
Sep 14, 2017, 9:08:08 PM9/14/17
to ack users

ack outputs nothing using crontab in linux.

In the crontab file (edited with sudo crontab -e):

39 20 * * * /ext/test110.sh

And cat /ext/test110.sh will show

#! /bin/sh

/usr/bin/ack "localhost" /etc/hosts > /ext/1.t
which ack > /ext/2.t

After cron, there are 1.t and 2.t in /ext

cat 2.t will output /usr/bin/ack; However, nothing in 1.t.

If I run ack "localhost" /etc/hosts > /ext/3.t in bash (4.3.30) or sh directly, it will output: 127.0.0.1 localhost

It seems ack cannot work with cron. where is the bug? BTW, grep works on this situation. Thank you.

uname -a:

Linux xxx 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux

ack --version : ack 2.14, Running under Perl 5.20.2 at /usr/bin/perl

Thank you.


Andy Lester

unread,
Sep 14, 2017, 9:13:10 PM9/14/17
to ack-...@googlegroups.com

In the crontab file (edited with sudo crontab -e):

So you’re running this under root’s user account.  My first guess would be that for some reason root’s pathing can’t see ack, or maybe can’t find the perl that ack needs.

/usr/bin/ack "localhost" /etc/hosts > /ext/1.t
You could try just invoking

    /usr/bin/ack —help > /etc/1.t

and see if ack runs at all.

It seems ack cannot work with cron. where is the bug? BTW, grep works on this situation. Thank you.

Even without this problem, I would suggest you use grep.  There’s no reason that I see not to.  ack is designed for interactive use with humans, and not at all for shell scripts.  

Andy

Zhilong Jia

unread,
Sep 14, 2017, 9:28:23 PM9/14/17
to ack users
` /usr/bin/ack —help > /ext/1.t` works.
ack can search r or python scripts directly, which is powerful. The problem is I can use ack in the console with redirection (which means not only interactive), but not in cron. Thank you for your reply.

Andy Lester

unread,
Sep 14, 2017, 9:33:43 PM9/14/17
to ack-...@googlegroups.com
On Sep 14, 2017, at 8:28 PM, Zhilong Jia <zhilo...@gmail.com> wrote:

` /usr/bin/ack —help > /ext/1.t` works.
ack can search r or python scripts directly, which is powerful.

I’m not sure what you mean by "ack can search r or python scripts directly”.  


I understand that you’re not able to get this working under cron, and I’m not going to be able to debug it here via the mailing list.  Can you please submit it as an issue here?  https://github.com/beyondgrep/ack2



Zhilong Jia

unread,
Sep 14, 2017, 9:43:06 PM9/14/17
to ack users
Reply all
Reply to author
Forward
0 new messages