This is (yet) another query about cron. I have referred to the guide on this site before posting here, but I still can't get this script to work. It is designed to suspend the PC when activity on certain network ports stop. The script runs as listed perfectly in a normal shell. I transferred the environment variables to the crontab as listed below.
Apologies if this is an obvious question but I can't seem to figure this out. The guides I have seen suggest putting environment variables in the crontab.
# set shell to bash
SHELL=/bin/bash
# copy PATH from bash
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
# set up gt-netscan variables in here instead of /etc/environment
STDBY_ON=1
STDBY_CT=0
STDBY_LIM=5
01 * * * * /usr/local/include/gt-netscan
Here is the script:
#!/bin/bash
if [[ "STDBY_ON" -eq 1 ]]; then
packets=0
interface="eth0" #interface to listen on
packets=$(timeout 5 sudo tcpdump -c 100 -n -i $interface port 22 | grep -c 192.168.7.4)
if [[ "$packets" -eq 0 ]]; then
let "STDBY_CT+=1"
echo "No packets, loop $STDBY_CT count" >> /var/log/gt-netscan
else
let "STDBY_CT=0"
echo "Loop reset: $packets packets detected" >> /var/log/gt-netscan
echo $(date) >> /var/log/gt-netscan
fi
if [[ "$STDBY_CT" -gt "$STDBY_LIM" ]]; then
echo "Suspending, no activity for 20 minutes on $interface." >> /var/log/gt-netscan
echo $(date) >> /var/log/gt-netscan
let "STDBY_CT=0"
sudo pm-suspend
fi
fi
exit
Any help will be greatly appreciated.
EDIT 1: as requested,here's the output from var/log/syslog grepped for the script name (gt-netscan).
Jan 31 11:35:15 big-boss kernel: [ 9.231242] init: gt-netscan main process (814) terminated with status 2
Jan 31 11:35:19 big-boss kernel: [ 13.188657] init: gt-netscan main process (2718) terminated with status 2
EDIT 2: output from 'stat /usr/local/include/gt-netscan'
File: `/usr/local/include/gt-netscan'
Size: 995 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 664072 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2015-01-31 12:01:01.979605807 +0000
Modify: 2015-01-27 23:32:07.027119674 +0000
Change: 2015-01-27 23:32:07.035119674 +0000
Birth: -
stat /usr/local/include/gt-netscan
say?