LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-17-2010, 02:55 PM   #1
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

Rep: Reputation: 30
crontab not running script


I put below line in a sh file
----------------------------------
#!/bin/bash
HOSTS=172.16.14.1

COUNT=4

for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)" >> /var/sun/status
fi
done
------------------------------------------

after that I edited crontab -e (logged as root) and entered a like below in that

01 * * * * root /var/sun/./chk.sh > /dev/null 2>&1

but thr is no output in file /var/sun/status

when I manually run that script it paste output in said file.

what's wrong ?
 
Old 05-17-2010, 03:08 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
cron sets a very limited $PATH. The workaround is either to set the usual $PATH in the script with export PATH=whatever or to prefix all commands with their full path, example change ping to /bin/ping.
 
Old 05-18-2010, 02:11 AM   #3
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
01 * * * * root /var/sun/./chk.sh > /dev/null 2>&1
I can see many things
1. This script will execute 1st minute of every hour. So You have to wait for an hour to get some output from it.

2. /var/sun/./chk.sh, Is the part in Color Red Intentional. Although it will work.

3. Rather than directing the STDOUT and STDERR to /dev/null redirect them to a file. This might help in finding possible errors.
 
Old 05-18-2010, 06:01 AM   #4
sunlinux
Member
 
Registered: Feb 2006
Distribution: RHCL 5
Posts: 239

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by PMP View Post
Code:
01 * * * * root /var/sun/./chk.sh > /dev/null 2>&1
I can see many things
1. This script will execute 1st minute of every hour. So You have to wait for an hour to get some output from it.

2. /var/sun/./chk.sh, Is the part in Color Red Intentional. Although it will work.

3. Rather than directing the STDOUT and STDERR to /dev/null redirect them to a file. This might help in finding possible errors.


what is I want to execute above script every minute ?
 
Old 05-18-2010, 06:20 AM   #5
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
*/1 * * * * root /var/sun/./chk.sh > /dev/null 2>&1
 
Old 05-18-2010, 06:21 AM   #6
geovg
Member
 
Registered: Mar 2010
Posts: 40

Rep: Reputation: 1
Quote:
Originally Posted by sunlinux View Post
what is I want to execute above script every minute ?
use,

* * * * * /bin/sh /var/sun/./chk.sh > /dev/null 2>&1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM
Bash script not running within crontab job WrightExposure Linux - General 3 01-23-2007 06:28 PM
error running script on crontab haora Linux - Newbie 3 03-11-2005 04:02 PM
Shell script running via crontab problem. thetruethugg Linux - Software 13 12-19-2003 08:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration