Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Accessing Isql command via VI editor

UNIX for Beginners Questions & Answers


Tags
isql, solved, sybase, unix, vi

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-10-2016
Xworks Xworks is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 October 2016, 9:52 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Wrench Accessing Isql command via VI editor

Hi Guru's,

I'm new at Unix. I am tasked to monitor the filesystem utilization on OS level (Unix) and DB (Sybase) for multiple systems. I am thinking to use vi editor and make a file, execute that file and all the file systems I need to monitor will be be shown.

My script inside vi goes in this flow.


Code:
df -h 
su - sybsid
isql -Usapsa -SSID -w999 -PPasswordSID -X 
df -h
su - sybpg1
isql -Usapsa -SPG1 -PMaster4PG1 -w999 -X <<-EOS
declare @pagesize numeric(19,0)
select @pagesize=(select @@maxpagesize)
SELECT "Database Name" = CONVERT(char(30), db_name(D.dbid)),
"Data Size MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN U.size*@pagesize/1048576 END),10,1),
"Used Data MB" = STR(SUM(CASE WHEN U.segmap != 4 THEN size - curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs)END)*@pagesize/1048576,10,1),
"Data Full%" = STR(100 * (1 - 1.0 * SUM(CASE WHEN U.segmap != 4 THEN curunreservedpgs(U.dbid, U.lstart, U.unreservedpgs) END)/SUM(CASE WHEN U.segmap != 4 THEN U.size END)),9,1) ,
"Log Size MB" = STR(SUM(CASE WHEN U.segmap = 4 THEN U.size*@pagesize/1048576 END),10,1),
"Free Log MB" = STR(lct_admin("logsegment_freepages",D.dbid)*@pagesize/1048576,10,1),
"Log Full%" = STR(100 * (1 - 1.0 * lct_admin("logsegment_freepages",D.dbid) /
SUM(CASE WHEN U.segmap = 4 THEN U.size END)),8,1)
FROM master..sysdatabases D,
master..sysusages U
WHERE U.dbid = D.dbid
AND ((D.dbid != 2))
GROUP BY D.dbid
ORDER BY db_name(D.dbid)
go
EOS

When executing above script, it does load filesystem in OS level (the df -h one) and accesses su - sybsid line however don't automatically enter isql.
seems like it stuck on su - sybsid line. When i execute "exit" in sybsid i get this error "isql: command not found".

Hope you could help me out with my script to automate my monitoring for multiple systems..

Thank you very much.



Moderator's Comments:
Accessing Isql command via VI editor Please use code tags as required by forum rules!

Last edited by RudiC; 06-11-2016 at 04:43 AM.. Reason: Added code tags
Sponsored Links
    #2  
Old Unix and Linux 06-11-2016
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 October 2017, 10:47 AM EDT
Location: Aachen, Germany
Posts: 11,461
Thanks: 308
Thanked 3,554 Times in 3,271 Posts
That looks like a misunderstanding followed by a flawed setup and/or security issue.

su - sybsid will create an interactive session for user sybsid, and you should see - without mentioning it above - that user's prompt sitting and waiting for your input. You entering "exit" will end the session. Did you consider su's -c option?

Then, the former user, whoever that might be, tries to run isql, resulting in command not found. That can be on purpose: user is not intended to run it, or it is a missing/wrong PATH and/or alias definition.

I hope I could point you in the right direction to solve your problem.
Sponsored Links
    #3  
Old Unix and Linux 06-11-2016
Xworks Xworks is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 October 2016, 9:52 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Hi RudiC

Thanks for your reply, sorry to get you confused. Reason why i execute "exit" on su - sybsid line is to just get any response or error in my script as to why it does not execute the isql line.

Is the su - sybsid line really interactive? Meaning i really should execute isql line everytime i run the file in order for my script to continue? I was thinking of eliminating any interaction so it does save me time as i need to do these on multiple systems.

Appreciate your reply. Thanks so much.
    #4  
Old Unix and Linux 06-11-2016
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 October 2017, 10:47 AM EDT
Location: Aachen, Germany
Posts: 11,461
Thanks: 308
Thanked 3,554 Times in 3,271 Posts
Did you consider su 's -c option?
Quote:
-c, --command COMMAND
Specify a command that will be invoked by the shell using its -c.
Sponsored Links
    #5  
Old Unix and Linux 06-11-2016
Xworks Xworks is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 October 2016, 9:52 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot! That worked perfectly. Linux
however this time my script for monitoring DB file system utilization is the new problem. when i enter isql, i just simply paste the "long script" (when i do this manually) but this time it's not executing automatically. Seems vi is still reading it as Unix script whereas should be in isql.

any advise on this?

---------- Post updated at 08:16 PM ---------- Previous update was at 07:25 PM ----------

Hi RudiC

I solved my issue above, just echo the whole 'long script'. My problem is now solved.

Thank you so much for your help! Linux
Sponsored Links
    #6  
Old Unix and Linux 06-11-2016
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 October 2017, 10:47 AM EDT
Location: Aachen, Germany
Posts: 11,461
Thanks: 308
Thanked 3,554 Times in 3,271 Posts
Let's get some terms right, as from reading your post I get the feeling not all is crystal clear to you:

df -h does not "load filesystem in OS level", it "... displays the amount of disk space available on the file system ...". A look at man df might help.

vi is one among many text editors. It does not execute scripts nor programs but allows you to create and modify text files. These, if consisting of commands and shell builtins, are known as scripts and, if having the "executable" permission set, can be executed (better: interpreted) by the shell. Just like commands.

Not having the slightest clue about isql I guess it to be an sql interpreter. You can run it interactively to perform ad hoc queries etc., or have it read and interpret sql scripts. One among others is the way you show in post#1 using a "here document".

I'd propose to prepare a shell script very similar to the one in post#1, make it executable, test it interactively, and, when happy with it, run it using su's -c option.


EDIT: Looks like my post crossed your recent update of your post...

Last edited by RudiC; 06-11-2016 at 08:34 AM..
Sponsored Links
    #7  
Old Unix and Linux 06-11-2016
Xworks Xworks is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 October 2016, 9:52 PM EDT
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Hi RudiC

Thank you for your insights. I took note of it. Now i have background on these commands using man.

I'd love to see your version of script.

Please send it to me so i can test, compare and play with it.

Huge thanks!
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to handle NULL value output from ISQL command? Sharma331 Shell Programming and Scripting 4 07-09-2014 06:43 AM
How to get the output of a ISQL command in a variable? Sharma331 Shell Programming and Scripting 2 06-27-2014 07:06 AM
FTP connection refused from text editor while accessing AIX server . rmkganesh AIX 2 10-26-2012 03:29 PM
Error while executing isql command on RHEL4 roopalidalvi231 Red Hat 4 04-13-2012 04:17 AM
isql command not working in Linux 64bit roopalidalvi231 Red Hat 5 04-04-2012 11:49 AM



All times are GMT -4. The time now is 10:50 AM.