The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in running shell script in cron sari Shell Programming and Scripting 3 04-16-2008 04:09 AM
Is it possible to have more than one Cron in shell script? Yamini Thoppen AIX 4 12-17-2007 03:23 AM
Problem with scheduling a shell script on cygwin using cron shash UNIX for Dummies Questions & Answers 4 08-09-2007 06:08 PM
executing shell script from the cron abNORMal HP-UX 2 06-15-2006 02:54 PM
gzip in shell script called by cron hbau419 Shell Programming and Scripting 2 02-05-2002 07:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-02-2007
deppy82 deppy82 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 2
Shell script & cron

Hi everybody!

I'm struggling against a script that won' t work right in a cron job

this is my script:

Code:
cat serverlist | while read arg
do
        if [ -n $arg ]
        then
                echo "$arg"
                ping -c 4 $arg >> /dev/null
                if [ $? != 0 ]
                then
                        msg_body="msg_subst"
                        host=`nslookup $arg | grep name | sed 's/.*name = //'`
                        cat message | sed "s/srv/$arg - $host/" > msg_subst
                        cat admins | while read line
                        do
                                if [ -n $line ]
                                then
                                        echo "$line"
                                        mail -s Servizio_controllo_server $line                                                                              < "$msg_body"
                                fi
                        done
                fi
        fi
done
this script works fine ( it sends an e-mail when it can' t ping a host) if lanched with prompt, but seems that if i run it in a cron job, it doesn' t ping any host!!! Even if They are alive!!!
I have tried anything on it, but nothing helped.
Thank you for the help and sorry for my english!!
  #2 (permalink)  
Old 08-02-2007
benefactr benefactr is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 71
First you should put the full path to serverlist, as cron wouldn't know where the file resides. See if this fixes it.

You are probably running it from the path where the file exists and that is why it works fine when manually running it.
  #3 (permalink)  
Old 08-02-2007
deppy82 deppy82 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 2
The matter is that the script fully works even when launched in cron.
The focus problem is that the ping command returns always a non-zero value and the then block is always executed.
This bug only occurs when i run the script from cron.
P.S. my O.S. id FreeBSD 6.2
  #4 (permalink)  
Old 08-02-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
read the cron FAQ first.
NOTE: looks like your 'serverlist', 'message' and 'admin' files have no absolut paths and make assumptions of their location - you might want to revist those.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0