I made a script called hello.sh and it contains the following:


printf "$( arp-scan --interface=eth0 --localnet )\n"
printf "test\n"

after making it executable (chmod o+x) and running it (./hello.sh >> file.txt) I get the correct output in file.txt (which is the arp-scan result and the string "test"). But after adding the following line to crontab -e:

*/1 * * * *  /path/to/hello.sh >> /path/to/file.txt

I get the following output:




As you can see there is a empty string returned by the arp-scan part. How can I get arpscan working with cron?

Additional info: Everything is done after logging in as sudo (sudo -i). arp-scan needs sudo. I am running this on Fedora 20.

  • 3
    Provide the full path to arp-scan in the script, cron runs with a minimal environment and it may not be in the path. Also, do you mean you've added this to root's crontab rather than your own? cron isn't going to honour anything to do with sudo if you add this to your own crontab. – EightBitTony Feb 19 '16 at 15:52
  • What EightBitTony said. Also, why create a script for it at all? Just run arp-scan directly from cron. – terdon Feb 19 '16 at 15:53
  • @EightBitTony It worked by giving the full path. @ terdon this was a simplified version of the script (stackexchange asks for this). The output of arp-scan is actually processed by the real script. – Mehdi Nellen Feb 19 '16 at 15:57

cron runs with a very minimal environment and a reduced path.

It's always safest in scripts designed to be executed by cron to ensure all commands have the full path provided, or the script sets its own PATH variable.

Try adding the full path to the arp-scan command.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.