issue while configuring a script in the cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue while configuring a script in the cronjob
# 1  
Old 04-09-2009
issue while configuring a script in the cronjob

Hi all,

I have written the following script which will try pinging to almost 24 nodes and when the connectivity is down it sends me an alert saying the node is down. It also gets me a trace route information and a contact information.
When i run this script manually it actually works. But when i have assigned it in cronjob and when it gets executed it throws up mails for all 24 nodes saying all are done which is not the case when executing it manually. I suspect that the if condition b=$? seems not to be working in this case or in other words the value of b goes greater than zero which is again not happening int eh case of running the script manually. Can you suggest me on this?

Can you assist me in this. I am a bit confused on this as i have checked all the paths i have referred in the scripts.








NODEINFODIR=/ndm1/work/scripts/testdir/venki
cd $NODEINFODIR
i=1
while [ $i -le 24 ]
do
k=`cat /ndm1/work/scripts/testdir/venki/iplist|head -$i|tail -1`
echo $k
v=`ping $k|grep alive`
b=$?
echo $b >>dhadha
if [ $b -gt 0 ]
then
traceroute $k > "$NODEINFODIR/tracerouteinformationof$k.txt"
cat $NODEINFODIR/filename | grep $k | cut -f1-8 -d '' > "Contactinformationfor$knode.txt"
(echo "Node $k is down"; uuencode Contactinformationfor$knode.txt Contactinformationfor$knode.txt;uuencode tracerouteinformationof$k.txt
tracerouteinformationof$k.txt)| mailx -s " Node connectivity " venkita.venkatarama@gmail.com
else
echo " The connectivity is live "
fi
i=`expr $i + 1`
done
# 2  
Old 04-10-2009
ya ofcourse $? won't work in your case since $? will return the exit status of privious command and your previous command is assing something to a variable which will always return 0
so write only
Code:
ping $k |grep alive >/dev/null
b=$?

# 3  
Old 04-10-2009
Actually that was just to test the values i get. But even afte i remove that the error remains the same.

if you see the same script works while running manually but is is not in the case while it is set in cronjob .

Would there be a possible reason for it?
# 4  
Old 04-10-2009
I would suggest a small change that should remove the issue with the exit command.
Code:
#v=`ping $k|grep alive`
#b=$?
#echo $b >>dhadha
#if [ $b -gt 0 ]
# # the '-c' option will return the number of times "alive" was found.
v=`ping $k|grep -c alive`
if [ $v -gt 0 ]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SuSE

Facing issue configuring network

Please let me know how to configure network in suse Linux, I have configured the network using ifup and network manager, it is not giving any error but not working, using suse Linux 11.0 sp3 I have checked network connectivity is working. (0 Replies)
Discussion started by: manoj.solaris
0 Replies

2. Shell Programming and Scripting

Cronjob issue

Dear expert, I have script named as test.sh in HP-UX i am using like 00 00 */15 * * : but its cronjob giving error i want to schedule my script for each 15 days interval exactly. for example:15 jan,30 jan,15 feb, 2 march, 17 april...etc. quick response must be highly appreciated. ... (8 Replies)
Discussion started by: Jewel
8 Replies

3. Shell Programming and Scripting

Facing Issue after configuring logrotate

Hi, I have a logrotate configuration which rotates a log every night 1 min before midnight, but somehow its not working and unfortunately not showing any error message as well. Sharing the code for the cron job as well as the conf file, I am using, if some one coule help me..whats wrong with... (2 Replies)
Discussion started by: Neeryan
2 Replies

4. Cybersecurity

Heartbeat configuring issue

hi i'm configuring linux heartbeat in my two redhat boxes i have below few things to clarify can i set up heartbeat between two different notworks? (e.g primary server IP is 192.168.x.x and secondary server IP is 10.48.X.X) i got below error in my secondary server once primary is down ... (2 Replies)
Discussion started by: asela115
2 Replies

5. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

6. Shell Programming and Scripting

cronjob issue

Hi, I am able to run a.sh script manually but they are not getting invoked from the crontab here is cronjob entry 15 03 * * * /Feed/bin/a.sh >/Feed/logs/log.txt logs.txt is empty Please Advice (7 Replies)
Discussion started by: mad_man12
7 Replies

7. SuSE

SLES10 - cronjob issue?

I installed some software (zenworks linux management) and it apparently set up a cronjob for a postgresql database command. The job runs every 4 hours and fails everytime sending root mail... the problem I have is I cant find this job anywhere. ive looked in all the usual cronjob places but... (1 Reply)
Discussion started by: trey85stang
1 Replies

8. Solaris

Creating a CronJob Script

Hi All, Good Day. Anyone can guide me on how to create a cronjob script that run prstat -a and vmstat 10 10 on the certain time of the day and produce a log which will be kept in a specific directory? I am running on Solaris 10. Thanks. (2 Replies)
Discussion started by: ronny_nch
2 Replies

9. Shell Programming and Scripting

cronjob inside the script

Hiii, can nayone provide me the sample script which can do the following tasks--- I will apperciate if anyone give me their valuable inputs.I guess this is not at all a big task for the experts in the forum so kindly help me out in this. (3 Replies)
Discussion started by: namishtiwari
3 Replies

10. HP-UX

Facing an issue related to cronjob

Dear All, I am facing an issue related to cronjob and explained below is the case study: 1. I have a java class named "DmCheckRenditionQueue.java" and placed under "/cpc/documentum/product/5.2.5/tomcat/webapps/rendition" 2. When I am using the command "/usr/openv/java/jre/bin/java -cp... (1 Reply)
Discussion started by: parindam
1 Replies
Login or Register to Ask a Question