issue with cron and a simple sh script

Pietro Sammarco pietro.bsdml at gmail.com
Fri May 30 15:28:41 UTC 2014


Hello everyone,

I am not sure this is a specific i386 issue, however,  I decided to go
with this section because this laptop is a i386 one and I didn't know
where else to post this.

Since yesterday night I have been encountering a problem with making
cron executing a very simple sh script that does nothing more than
just checking if google.com is pingable, if not it will take the wlan0
down, up again and run dhclient on it.

Now the script works just fine if you execute it manually, but for
some reason I couldn't figure out why it doesn't with cron.

According to the cron logs the script gets executed every minute as it
is supposed to be, but if I bring the wlan0 down to see if it is
working, nothing happens. I have also tried adding it as cronjob with
the root user or with other users added to "wheel" and sudoers, but it
doesn't make any difference.

This is certainly not the first time I have used cron, and I can't
seem to figure out what is happening here, at the same time I don't
get any erros in /dev/null, everything seems to be running just fine,
when it's not.

Here I have collected some logs,

Thanks.

#crontab -u pietro -e
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

MAILTO="pietro"
* * * * * $HOME/.shrc; sh /var/cron/tabs/resumewlan.sh >/dev/null


#/var/log/cron

May 30 10:06:42 HP-laptop cron[3188]: (tmp.1856) ORPHAN (no passwd entry)
May 30 10:06:42 HP-laptop cron[3188]: (resumewlan.sh) ORPHAN (no passwd entry)
May 30 10:06:42 HP-laptop cron[3796]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:08:47 HP-laptop cron[3876]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:09:38 HP-laptop cron[3882]: (root) CMD (/usr/libexec/atrun)
May 30 10:09:38 HP-laptop cron[3883]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:09:59 HP-laptop cron[3889]: (operator) CMD (/usr/libexec/save-entropy)
May 30 10:09:59 HP-laptop cron[3891]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:11:21 HP-laptop cron[3904]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:12:21 HP-laptop cron[3909]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:13:47 HP-laptop cron[3914]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:14:47 HP-laptop cron[3920]: (root) CMD (/usr/libexec/atrun)
May 30 10:14:47 HP-laptop cron[3921]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:15:47 HP-laptop cron[3929]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)
May 30 10:16:47 HP-laptop cron[3941]: (pietro) CMD ($HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null)

#cron -x bit,ext,load,misc,pars,proc,sch > cron.log

user [pietro:1001:0:...] cmd="$HOME/.shrc; sh
/var/cron/tabs/resumewlan.sh >/dev/null"
[3188] TargetTime=1401463200, sec-to-wait=56
[3188] do_command($HOME/.shrc; sh /var/cron/tabs/resumewlan.sh
>/dev/null, (pietro,1001,0))
[3188] main process returning to work
[3188] TargetTime=1401463200, sec-to-wait=56
[3188] sleeping for 56 seconds
[3947] child_process('$HOME/.shrc; sh /var/cron/tabs/resumewlan.sh >/dev/null')
[3947] checking account with PAM
[3948] grandchild process Vfork()'ed
[3947] child continues, closing pipes
[3947] child reading output from grandchild
[3947] got data (2f:/) from grandchild
[3947] closing pipe to mail
[3947] got EOF from grandchild
[3947] waiting for grandchild #2 to finish
[3947] no more grandchildren--mail written?
[3947] child process done, exiting
[3188] sigchld...pid #3947 died, stat=0
[3188] sigchld...no children

$ echo $ENV
/home/pietro/.shrc

#script

#!/bin/sh

if ! [ `ping -c 4 google.com > /dev/null` ]; then
         ifconfig wlan0 down & ifconfig wlan0 up & dhclient wlan0
             #if ping timed out, takes down the wireless, takes it
back up and executes dhlient on it
fi


More information about the freebsd-i386 mailing list