hi can anyone pls look into this....shell script...
Pls find the error below:
> sh -n tmp
tmp: syntax error at line 28: `(' unexpected
isql -Usa -S$1 -P`grep $1 dbpassword|cut -d ":" -f3` -w2000 -b<<!
set nocount on
declare @i int
declare @dbname char(6)
declare @tmp int
if ($3="default")
set @i=3
else if ($3="log")
set @i=4
set @dbname="$2"
if (@dbname="tempdb")
begin
select @tmp=count() from sysusages where segmap!=7 and db_name(dbid)="$2"
if (@tmp <>(select count() from sysusages where db_name(dbid)="$2" and segmap=7))
begin
print "Pls use sp_extend segment to add $3 segment on the dev whose segmap!=7"
exit
end
else if(@tmp= 0)
begin
select "FREE SPACE: ",sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),
"Total Space: ",sum(size)/((10241024)/@@maxpagesize),"Server Name : ",@@servername from sysusages
where db_name(dbid)="$2" and segmap=7
end
end
go
!
select "FREE SPACE: ",sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),
"Total Space: ",sum(size)/((10241024)/@@maxpagesize),"Server Name : ",@@servername from sysusages
where db_name(dbid)="$2" and segmap=@i or segmap=7
go
select spid,cmd,physical_io,status from master..sysprocesses where cmd not like "AWA%"
go
!
isql -Usa -SCHI_DRUM_MONITOR -Ddba_database -Psy91base -w2000<<!
select top 20 yyyymmdd,allocated_to_db,unused_in_db,used_in_db from space_usage_history where
instname="$1" and db="$2" order by yyyymmdd desc
go
!
select "FREE SPACE: ",sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(1024*1024))),
"Total Space: ",sum(size)/((1024*1024)/@@maxpagesize),"Server Name : ",@@servername from sysusages
where db_name(dbid)="$2" and segmap=@i or segmap=7
You should put the entire query in double-quotes, not just some parts. And put single-quotes around the $2 expression because this might be a string that needs quoting. (If Oracle needs double-quotes, then use \" instead of ').
select "FREE SPACE:,sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(1024*1024))),Total Space: ,sum(size)/((1024*1024)/@@maxpagesize),Server Name : ,@@servername from sysusages
where db_name(dbid)='$2' and segmap=@i or segmap=7"
1> select "FREE SPACE: ,sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),Total Space: ,sum(size)/((10241024)/@@maxpagesize),Server Name : ,@@servername from sysusages where db_name(dbid)='EMbsDb' and segmap=3"
2>
3> go
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FREE SPACE: ,sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),Total Space: ,sum(size)/((10241024)/@@maxpagesize),Server Name : ,@@servername from sysusages where db_name(dbid)='EMbsDb' and segmap=3
(1 row affected)
1>
------------------------
The statement when run in isql (sybase database) gives desired results but when included int the script -its throwing errors:
1> select "FREE SPACE: ",sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),"Total Space: ",sum(size)/((10241024)/@@maxpagesize),"Server Name : ",@@servername from sysusages where db_name(dbid)="EMbsDb" and segmap=3
2> go
------------ ----------- ------------- ----------- -------------- ------------------------------
FREE SPACE: 0 Total Space: 7700 Server Name : RER_PROD_125
So you need to double-quote words inside your double-quoted script. Fine:
select "\"FREE SPACE:\",
sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(1024*1024))),
\"Total Space: \",
sum(size)/((1024*1024)/@@maxpagesize),
\"Server Name :\",
@@servername from sysusages
where db_name(dbid)='$2' and segmap=@i or segmap=7"
Anyways ...Thank you for quick reply i think sybase doesnt accept this esc sequence.
1> select "\"FREE SPACE:\""
2> go
Msg 102, Level 15, State 1:
Server 'RER_QA_125', Line 1:
Incorrect syntax near '\'.
1>
1> select "\"FREE SPACE:\",
2> sum(curunreservedpgs(dbid,lstart,unreservedpgs)*(@@maxpagesize/(10241024))),
3> \"Total Space: \",
4> sum(size)/((10241024)/@@maxpagesize),
5> \"Server Name :\",
6> @@servername from sysusageswhere db_name(dbid)='FiTraderDb' and segmap=3"
7> go
Msg 102, Level 15, State 1:
Server 'RER_QA_125', Line 1:
Incorrect syntax near '\'.
There is an "isql" line completely missing after line 27 (the first line containing only "!"). In shell the "!" terminates each <<! .
The original error message is because the "select" line on line 28 is being interpreted by shell not "isql".