Bash script not working with Cron
by AlessioGiberti from LinuxQuestions.org on (#56ATR)
Hi, I wrote a bash script that sniffs the net traffic on one specific port. Its job is to send an alert via mail, using ssmtp, in case the traffic stops.
The issue is that if I run the script via shellCode:>>sh myscript.sh it works perfectly, while if I schedule its execution with crontab it doesn't work.
Code:#!/bin/bash
unset a
a=$(/usr/bin/timelimit -t10 /usr/sbin/tcpdump -i any -A -nn port 1883 and not host 192.168.183.58)
if [ -z "$a" ];
then
echo Non ho ricevuto niente!
/usr/sbin/ssmtp giberti@laboratoriomister.it < /home/alessio/text4CrisalideAlert.txt
fiAs you can see, I specified the complete paths for the external tools (timilimit, tcpdump and ssmtp). Looking at journalctl the issue seems to be 550 invalid domain. But launching it by hand it works!
Any help please?


The issue is that if I run the script via shellCode:>>sh myscript.sh it works perfectly, while if I schedule its execution with crontab it doesn't work.
Code:#!/bin/bash
unset a
a=$(/usr/bin/timelimit -t10 /usr/sbin/tcpdump -i any -A -nn port 1883 and not host 192.168.183.58)
if [ -z "$a" ];
then
echo Non ho ricevuto niente!
/usr/sbin/ssmtp giberti@laboratoriomister.it < /home/alessio/text4CrisalideAlert.txt
fiAs you can see, I specified the complete paths for the external tools (timilimit, tcpdump and ssmtp). Looking at journalctl the issue seems to be 550 invalid domain. But launching it by hand it works!
Any help please?