Need Help with isql in Shell Script

Hi Guys,

I need help with my code.

I am not able to find what the error is (tried debugging and everything).

#! /bin/sh

# MODSET_CLOSE
# Usage: modset_close

echo "Enter the Type of Modsets that needs to be Closed: "
read mod_typ

serv_name=`cat $mod_typ | awk '{ print $1 }'`
usr_name=`cat $mod_typ | awk '{ print $2 }'`
pswd=`cat $mod_typ | awk '{ print $3 }'`
db_name=`cat $mod_typ | awk '{ print $4 }'`
unx_usr_name=`cat $mod_typ | awk '{ print $5 }'`

echo $serv_name
echo $usr_name
echo $pswd
echo $db_name
echo $unix_user_name

cnt_temp=1

while [ $cnt_temp -ne 0 ]
do
	echo "Enter the Modset that needs to be Closed: "
	read mod_id
echo $mod_id
        if [ $mod_id ]
	then
		isql -S $serv_name -U $usr_name -P $pswd  -D $db_name -o temp_res << EOF1
		select status from modset where modsetid=$mod_id
		go
		exit
		EOF1
echo 1
		stat_cnt=`cat temp_res.txt | grep -cw O`
echo $stat_cnt
		if [ stat_cnt -eq 1 ]
		then
			isql -S $serv_name -U $usr_name -P $pswd  -D $db_name  << EOF2
			select * into #updtmgr_session from tmp_updtmgr_session exec updtmgr_session NULL,$unix_user_name,"y","y"
			go
			exit
			EOF2
echo 2
			isql -S $serv_name -U $usr_name -P $pswd  -D $db_name  << EOF3
			modset_close_any $mod_id
			go
			exit
			EOF3
echo 3
			isql -S $serv_name -U $usr_name -P $pswd  -D $db_name -o out_res << EOF4
			select modsetid,comments from modset where modseid=$mod_id
			go
			exit
			EOF4
echo 4
		fi
	fi
echo 5
	cat out_res.txt | grep -wi "closed by" | echo
echo 6

done 

I am getting the following error when run and i am not able to past the while loop ... i mean all the echo's are good till the while loop.

modset_close: syntax error at line 73: `end of file' unexpected

Please help ...

Closing labels, like EOF1 etc. should be right at the beginning of the line.

( also you cannot pipe into echo )

1 Like

Did not know that EOF should be placed at the start of the line and i have aligned according to if loop.

Anyways after moving the EOF to the start of the line, it worked like a charm.

Thanks a Lot for the Quick Reply. :b: :b: :b:

---------- Post updated 04-18-12 at 03:42 PM ---------- Previous update was 04-17-12 at 04:53 PM ----------

Hello

One more doubt ... I am not able to get the isql output to temp_res file ... i have tried all the different combinations as shown below, but could not get anywhere .... Please Help

isql -S $serv_name -U $usr_name -P $pswd  -D $db_name -o temp_res << EOF1
select status from modset where modsetid=$mod_id
go
exit
EOF1

isql -S $serv_name -U $usr_name -P $pswd  -D $db_name << EOF1 > -o temp_res
select status from modset where modsetid=$mod_id
go
exit
EOF1

isql -S $serv_name -U $usr_name -P $pswd  -D $db_name << EOF1 > temp_res
select status from modset where modsetid=$mod_id
go
exit
EOF1

temp_path="/.../.../.../.../temp_res.txt"
isql -S $serv_name -U $usr_name -P $pswd  -D $db_name -o temp_path << EOF1 
select status from modset where modsetid=$mod_id
go
exit
EOF1

In the script you have -o temp_res but then try reading the file with a different name cat temp_res.txt . Remember that this is unix and MSDOS-style file extensions have no special meaning.

ok,

Now i am finally using this code for isql ...

I am getting the input file, but the output is not going to the out file.

isql -S $serv_name -U $usr_name -P $pswd  -D $db_name -i temp_in.txt -o temp_out.txt

Juste remove space between the differents options and their associated values, like this

NOTE: you can add the option -i and -o to define the input sql file and the spool file