Script Runs fine but not giving any output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Runs fine but not giving any output
# 1  
Old 03-29-2010
Question Script Runs fine but not giving any output

Hi,

My script is running with no erros but not giving any output can anyonehelp.


Code:
#!/bin/ksh
. /home/application/bin/application.env
OUTFILE=Result.txt
PROD_PASSWORD=`${GET_PWD} -f ${PWD_FILE_PATH} -s ${PROD_SERVER} -u ${PROD_USER}`
echo "1)To get the book last loaded details "
read value
if [ $value -eq 1 ]
then
count=`cat input.txt | wc -l`
 
while [ $count -eq 1 ]
do
bookname=`cat input.txt | tail -$count |head -1`
/sbcimp/run/tp/sybase/prod/bin/isql -U${PROD_USER} -D${PROD_DB} -P${PROD_PASSWORD} -S${PROD_SERVER} -o$OUTFILE <<EOF
select p.period ,b.book from period p ,book b where p.id in( select b.id_period_cob from book where b.book in("$bookname"))
go
EOF
count=`expr $count - 1`
done

fi

input file has two entries.


pls guide me to get rid of this problem

Many thanx in advance!!

edit by bakunin: many thanks back for providing CODE-tags yourself from now on. You're welcome.

Last edited by bakunin; 03-29-2010 at 06:14 PM..
# 2  
Old 03-29-2010
Please you run the script with -x debug option, then give us the output.

Code:
/bin/ksh -x YOUR_SCRIPT

# 3  
Old 03-29-2010
Hi, found the issue, thanks for that

bookname=`cat input.txt | tail -'$count' |head -1` is not working

Cant we pass a variable to tail command,if not is there any alternate for this...

in this case count =2
# 4  
Old 03-29-2010
so you just need to print the whole line at $count?

Code:
bookname=`sed -n "$count  p"  input.txt`

# 5  
Old 03-29-2010
hope you didnt get it exactly.

I have a file with certain rows (input.txt)

from this i need to takeout 1 line at a time till the end and running the sql for every line(every bookname in input.txt)


so i opted for

bookname=`cat input.txt | tail -'$count' |head -1`

but here its throwing an error saying cant open 'count'

------------------
Code:
while [ $count != 0 ]
do
bookname=`cat input.txt | tail -$count |head -1`
/sbcimp/run/tp/sybase/prod/bin/isql -U${PROD_USER} -D${PROD_DB} -P${PROD_PASSWORD} -S${PROD_SERVER} -o$OUTFILE <<EOF
select p.period ,b.book from period p ,book b where p.id in( select b.id_period_cob from book where b.book in("$bookname"))
go
EOF
count=`expr $count - 1`
done

-----------------------

edit by bakunin: grrr, you know how to make the probably most lenient moderator around here angry! CODE-TAGS, PLEASE, and this is going to be my last warning!

Last edited by bakunin; 03-29-2010 at 11:37 PM..
# 6  
Old 03-29-2010
You can read a file line by line easily like this:

Code:
        while read LINE
        do
            echo "$LINE"
        done < $FILENAME

# 7  
Old 03-29-2010
its not working ,If i use this i get output only for the last line in input.txt Smilie

---------- Post updated at 09:18 PM ---------- Previous update was at 08:53 PM ----------

Sorry its working fine, as iam using isql so its overwriting the output all the time so iam getting the output for only last line from input.txt

Code:
OUTFILE=Result.txt
while read LINE
do
/sbcimp/run/tp/sybase/prod/bin/isql -U${PROD_USER} -D${PROD_DB} -P${PROD_PASSWORD} -S${PROD_SERVER} -o$OUTFILE <<EOF
select p.period ,b.book  from period p ,book b  where p.id in( select b.id_period_cob from book where b.book in("$LINE"))
go
EOF
done <input.txt

can you pls help in appending the output rather than overwriting

edit by bakunin: same here, use CODE-tags when posting code or code-snippets

Last edited by bakunin; 03-29-2010 at 11:38 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sql command inside shell script runs without giving anything back as outout

#!/bin/sh # This script returns the number of rows updated from a function echo "The execution is starting ....." sqlplus -silent $UP <<EOF set serveroutput on set echo off set pagesize 0 VAR no_rows_updated NUMBER; EXEC :no_rows_updated :=0; DECLARE CURSOR c_update is SELECT * FROM... (4 Replies)
Discussion started by: LoneRanger
4 Replies

2. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

3. Shell Programming and Scripting

Part of the Shell script is not running via crontab, runs fine manually

Hello Team, As a part of my job we have made a script to automate a service to restart frequently. Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Discussion started by: gowthamakanthan
18 Replies

4. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

5. Shell Programming and Scripting

Not the correct output, works fine via CLI, not inside the script.

Guys, I need you help please. The script below is not working correclty for checking via a awk/if statement . Can you tell me what i am doing wrong in the script code "if($1 == "$RETENTION_LEVEL") " Syntax RETENTION_LEVEL=`echo $LINE | cut -f2 -d" "` echo " ==============... (4 Replies)
Discussion started by: Junes
4 Replies

6. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 Replies

7. Programming

getting Segmentation Fault (core dumped) error but Program runs fine.

i am executing following program int main() { char str; FILE * fp; int i=0; ... (4 Replies)
Discussion started by: bhavesh.sapra
4 Replies

8. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

9. Shell Programming and Scripting

Script runs fine, but not in a cron

Okay, I have the following script that runs fine from a command line as well as an executable .sh file. It just moves any file/folder with movie* in the name to a folder called _Movies. The issue I'm running into is when it's call from a cron. find /mnt/HD_a2/BT/complete -iname "movie.*" -exec... (4 Replies)
Discussion started by: sammyk
4 Replies

10. UNIX for Dummies Questions & Answers

Script runs fine on UNIX Server...Not through MSK Tool kit on Windows Server

I have a .sh script which was running fine on all the UNIX Servers (AIX, SunSolaris). The script requires two mandatory parameters and many optional parameters. Now at a different client place who are on a Windows Server, when I try to execute the script through MKS Toolkit, there are couple of... (5 Replies)
Discussion started by: madhunk
5 Replies
Login or Register to Ask a Question