Seeing unexpected results when i run through cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Seeing unexpected results when i run through cronjob
# 1  
Old 02-04-2015
Seeing unexpected results when i run through cronjob

Hi

I'm having hard time here with below script. If i run script manually i see expected results but, if i keep this script in cron job i'm getting unexpected results. Unexpected results means even though condition is true,cronjob returning output of else condition.

This script and cronjob running on same linux server.Please let me know if i need to make any changes in code.



Code:
#!/bin/bash
#set -x
content1='bind successful'
file1=/cpt/app/scripts/test/sra
 
echo "testing" >>$file1 &
 
hn=ldrfvb1232.example.com
port=2507
user=dummy
pwd=xxxxxx
 
wallet_pwd=xxxxxx
 
amm=$(/cpt/apps/oracle/Oracle_Home/bin/ldapbind -h $hn -p $port -D "cn=$user" -w $pwd -U 2 -W "file:/cpt/apps/scripts/test/wallet" -P $wallet_pwd)
 
 
 
if [ "$amm" = 'bind successful' ]; then
 
echo  "$hn:$port-Health Check SUCCESS!" >>$file1 &
else
echo "$hn:$port-Health NOT-OK!" >>$file1 &
fi
exit

---------- Post updated at 08:01 PM ---------- Previous update was at 07:43 PM ----------

Can Anyone help on this?
# 2  
Old 02-04-2015
The first suspect is an environment variable. Take just the first lines of your script - put 'em in another file. add:

Code:
set >/myhome/dir/set.output

create a cronjob in the crontab. Let it run once. Remove the entry from the crontab - or comment it out at least. set.output MUST match the output of

set > t.txt

from your command line. try doing a diff. You can ignore RANDOM and some other junk.

From that point on you know what to do. Make your cronjob have the right stuff.
# 3  
Old 02-05-2015
Sharing jim mcnamara's first suspicion I can't see that script relying on a variable anywhere. All paths are absolute, all variables are defined locally... What do you get if you uncomment the set -x? What's the contents of $amm?

And, why do you echo from the background?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comm giving unexpected results

Hi I am comparing two files with comm -13 < (sort acc11.txt) < (sort acc12.txt) > output.txt purpose: Get non matching records which are in acc12 but not in acc11... TI am getting WRONG output. Is there any constraints with record length with comm? The above files are the two consective ... (2 Replies)
Discussion started by: vedanta
2 Replies

2. Shell Programming and Scripting

sed Unexpected results, missing first search item

I created 3 files with the identical data as follows dial-peer voice 9999 pots trunkgroup CO list outgoing Local translation-profile outgoing LOCAL-7-DIGITS-NO-PREPEND-97 preference 2 shutdown destination-pattern 9......$ forward-digits 7 dial-peer voice 10000 pots ... (6 Replies)
Discussion started by: popeye
6 Replies

3. Shell Programming and Scripting

Unexpected results with lists in GNU sed

I have been living with this problem with GNU sed v4.1.4 for a long time, but now I really need to figure it out. When using a list in either an address or a search, the expression is matching lower and upper-case letters. works as it should. For example, if I run sed -nr "// p"... (7 Replies)
Discussion started by: nctrader
7 Replies

4. UNIX for Dummies Questions & Answers

Find command gave unexpected results

Hi, I recently executed a find command that caused unexpected permission changes and we had to do a full system restore. Can someone please explain what this command would do? find /staging/admin/scr * -exec chmod 755 '{}' + It caused file permissions inside / to be modified strangely. ... (1 Reply)
Discussion started by: poornima
1 Replies

5. Shell Programming and Scripting

Unexpected results when triggered from cron

Following script gives different results when triggered from Cron compared to when triggered from command line. It is not able to assign values to some variables when triggered from cron. Can any one help? Its a very simple script Script - #! /bin/ksh sFile=$1 sEnv=$2 sWaitFile=$3... (1 Reply)
Discussion started by: sumeet
1 Replies

6. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

7. Shell Programming and Scripting

Unexpected Results (at least I did not expect them)

I have two sripts running in bash. The first one uncompresses log files and moves them to a working directory using uncompress -c and > output to new directory. It then creates one control record to assure our search returns a record. It then calls or executes the second script, which is a grep for... (6 Replies)
Discussion started by: altamaha
6 Replies

8. UNIX for Dummies Questions & Answers

Unexpected Results

Hello, When I run this script, here's what I get: Searching ... found 1111 2222 3333 ..... 7777 ..... 8888 9999 in 95_test Search completed. I expected only to see what number was found in the file, not including the ones not found. Thanks for your help! #!/bin/sh (1 Reply)
Discussion started by: SSims
1 Replies

9. Shell Programming and Scripting

Perl - Iterating a hash through a foreach loop - unexpected results

i've reworked some code from an earlier post, and it isn't working as expected i've simplified it to try and find the problem. i spent hours trying to figure out what is wrong, eventually thinking there was a bug in perl or a problem with my computer. but, i've tried it on 3 machines with the... (5 Replies)
Discussion started by: quantumechanix
5 Replies
Login or Register to Ask a Question