Shell script & cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script & cron
# 1  
Old 08-02-2007
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  
Old 08-02-2007
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  
Old 08-02-2007
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  
Old 08-02-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies

2. Shell Programming and Scripting

Running shell script via cron

Hi Guys, I do have a shell script that I scheduled to run via the cron but when the script don't run. But when I run the script manually it does run perfectly... What might be the problem? Thanks. (1 Reply)
Discussion started by: Phuti
1 Replies

3. UNIX for Dummies Questions & Answers

cron shell script question

Hi all, hopefully someone out there can give me some tips on how to resolve this I have a simple shell script who -u > /tmp/userlog one of the line stored in userlog when executing shell script manually: jim123 pts/24 2012-03-30 13:02 00:56 4131 (xya.dsfgds.com) one of the... (4 Replies)
Discussion started by: Linux_Novice
4 Replies

4. Shell Programming and Scripting

Bash Shell Script and Cron

How can I tell a script to only execute if the other scripts exits successfully? So "script A" executes and if it executes successfully (0),then "script B" will run or else "script A "executes and it exits unsucessfully (1) then "script B" will read return code (1) and will not execute ... (3 Replies)
Discussion started by: metallica1973
3 Replies

5. Shell Programming and Scripting

Shell script and Cron

Hi there, I have a script that pulls in a weather feed via FTP then writes the output to a file. This script is run everyday at 3pm by cron. Heres the shell script: #!/bin/sh HOST='ftp.weatheronline.co.uk' USER='my username' PASSWD='my password'... (2 Replies)
Discussion started by: mpk_3
2 Replies

6. Shell Programming and Scripting

Cron job shell script..

Hey Guys, i was trying out a shell script which has to remove a file for every 90 mins. this is the code i came up with . $ crontab -e file1 file1 contains 30 1 * * * * rm -r /folder1/folder2/somefile.txt Now i need the cron to run for every 90 mins. the problem with this is... (8 Replies)
Discussion started by: Irishboy24
8 Replies

7. UNIX for Advanced & Expert Users

Network Shell Script & Blade Logic & Network Security

I am going to take up a position in Data & Network Security. I would need to write network shell scripts doing the following task: Going to around 2000 servers and findout which groups has access to each servers and which ids are there in each group that has access. I need to implement... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. Shell Programming and Scripting

Cron execution of shell script

Hi Guys, Unable to run this script from the cron,although the same executes perfectly from the command line.Please help. #!/bin/sh #### aprintd alarm creation files ##### file=`date +%m%d%Y` pid=$$ echo "$pid" /u01/app/netboss/bin/aprintd/aprintd > $file & childpid=$!... (3 Replies)
Discussion started by: ashish.sharma
3 Replies

9. AIX

Is it possible to have more than one Cron in shell script?

Hi, can we have more than one cron in the shell script? If so pls let me know on what basis it is running. Whether on OS scheduling or the time scheduled in the cron file.Pls answer this query. Many Thanks (4 Replies)
Discussion started by: Yamini Thoppen
4 Replies

10. HP-UX

executing shell script from the cron

This isn't the usual problem that a shell script runs from the command line and not the cron. It's a little different. Among other things, the shell scrip executes my .profile to set a bunch of variables. It then does an env to ensure that it ran OK. There are echos in the shell script and... (2 Replies)
Discussion started by: abNORMal
2 Replies
Login or Register to Ask a Question