Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Debian 6.0.6. I edited root crontab a few days ago to add this line:

00,10,20,30,40,50 * * * * /root/Scripts/con_switch6.sh >> /var/log/con_switch_diario.log 2>&1

I'm connecting to this linux server using Putty. Meanwhile Putty console is opened and connected a line is generated inside the file "con_switch_diario.log" every 10 minutes (i.e., the script is running).

But when I closed that Putty console (i.e., the ssh connection is finished) and then I reopened it, I found that there aren't entries on that log file during that lapse of time. I did some tests and I found that when the console is closed the script is not executed by crontab.

The content of the script is this:

#!/bin/sh

IPcorreo="83.25.10.84"
IP1="192.168.10.125" 
IP2="192.168.10.154"
maxPloss="15"


IPfirewall=`traceroute -m 3 $IPcorreo | grep $IP1`

if [ $? -eq  0 ]
then
  echo "$IPfirewall: `date`"

  ploss=$(ping -q -w30 $IPcorreo | grep -o "[0-9]*%" | tr -d %) > /dev/null 2>&1

  if [ "$ploss" -gt "$maxPloss" ] 
  then
    /usr/bin/expect /root/Scripts/delete.exp
    sleep 60   
    echo "Switch Email: `date`" | mail -s System system@domain.com
  fi
else
  traceroute -m 3 $IPcorreo | grep $IP2
fi 

I don't know how could I fix this problem. Thank you for your help.

PS: in the same server, inside crontab I have defined others scripts... all they are running ok everyday. The only difference I found between them is they use

#!/bin/bash

instead of

#!/bin/sh

But even if I change it on my script to use bash I still have the same problem.

share|improve this question

migrated from stackoverflow.com Dec 24 '12 at 4:31

This question came from our site for professional and enthusiast programmers.

1 Answer 1

the problem is fixed. The cause was this line

ploss=$(ping -q -w30 $IPcorreo | grep -o "[0-9]*%" | tr -d %) > /dev/null 2>&1

once I changed it to

ploss=`ping -q -w30 $IPcorreo | grep -o "[0-9]*%" | tr -d %`

everything began to work fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.