Integrating bash with sql.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Integrating bash with sql.
# 1  
Old 08-12-2010
Integrating bash with sql.

Hi Guys,
I m just curious to know whether it is possible to store the output of a shell command to a database .

My main aim is to use a full capacity of sql language to analyze the output generated by shell script.
for example.

by storing the 5 instances of of top at different interval we can simply predict lot of things like.
Which process has Maximum cpu utilization, Which user has maximum processes running.
I think writting a scripts for doing these tasks will require lot of overheads and file creation.

I hope i have clear my point .Please reply if any further clarification is required.
# 2  
Old 08-12-2010
Data such as cpu utilization are transitory, and as such aren't very useful in themselves.
Shell script, and languages such as perl are more than adequate to process simple numbers such as cpu utilization to provide trend data, which can then be stored in a database or indeed flat files for later use. Can you try to explain why you are trying to use SQL in this instance ? Ie, what functionality SQL brings to this task that cannot be accomplished in other ways ?

Thx
This User Gave Thanks to citaylor For This Post:
# 3  
Old 08-12-2010
MySQL for instance has the commandline mysql tool to execute queries from the commandline. Most major DBMS providers supply something like it.
# 4  
Old 08-13-2010
Quote:
Originally Posted by citaylor
Data such as cpu utilization are transitory, and as such aren't very useful in themselves.
Shell script, and languages such as perl are more than adequate to process simple numbers such as cpu utilization to provide trend data, which can then be stored in a database or indeed flat files for later use. Can you try to explain why you are trying to use SQL in this instance ? Ie, what functionality SQL brings to this task that cannot be accomplished in other ways ?

Thx
For example.
Output of top shows process id and amount of CPU consumed by it.
If i write a script for telling the maximum cpu utilization its pretty simple but how would i get something very complex like getting cpu utilization of particular process id over the period .
Group by command and other functions like select max(cpu_uti),process)_id from toptable group by (process id)

This is just a one example with sql you can have lot of options. I guess sqlite is a tool i should go for.
# 5  
Old 08-13-2010
You might also want to investigate sar, available on most Unix implementations (part of the sysstat package in most GNU/Linux distros), which can do per-process accounting with the sadf command.
# 6  
Old 08-13-2010
may be you can try 'isql' command to interact with a database from a shell.

I am sure though.
# 7  
Old 08-18-2010
This can be done by capturing the output of ps command and then storing it in a database table.
I use Perl DBI to store the results and then compute the desired output from it.

I use UNIX95 variable as certain options dont work with ps like -o.

If you need any help on using this , pls post it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Integrating bash shell

Hi folks... I am working on a project where I need to have online bash bash shell integrated in my web page. I am not clear of how to do it. can any one suggest?? The UI needs to be developed in c#. (11 Replies)
Discussion started by: keerthi koneru
11 Replies

2. Shell Programming and Scripting

Passing string from SQL to a BASH script

OS Solaris 10, DB oracle 10g Hello, We currently have a BASH script that runs and moves image files from a remote server to the local db server. A snippet of the code shows that we are picking up all Images that are 'mtime -1' some code... for file in `ssh user@10.200.200.10 'find... (3 Replies)
Discussion started by: JonP
3 Replies

3. Shell Programming and Scripting

Help with integrating shell script with sendmail

Hi friends, I want to converting a task ,of making few words in my task mail bold and underlined sometimes, automated through sendmail. I have never used sendmail/mailx before. What i want is my ouput which looks like below: +++++++++++++++ DETAILS: sqlid:6mbiosdfsdff parsing_schema_name:... (1 Reply)
Discussion started by: kunwar
1 Replies

4. Programming

Integrating Jconsole with Eclipse

Hi Guys, I was hoping someone has integrated Eclipse with jconsole to monitor their applications. I have not seen this in action . Any help is much appreciated http://images.devshed.com/fds/smilies/smile.gif Thanks (0 Replies)
Discussion started by: aish11
0 Replies

5. Shell Programming and Scripting

Convert sql output to csv file via bash tools

hi Can anybody help me with converting such structure into csv file for windows : BAT_ID ID_num CVS_LINE A_SEG SKILL_TO A_CUSTOMER_TYPE --------- ---------- --------------------------------- ---------- ------------------ ----------- 14-MAY-11 777752 ... (4 Replies)
Discussion started by: kvok
4 Replies

6. UNIX for Dummies Questions & Answers

Integrating bash script into php (page)

I have written a bash script...now i need to call the script from php page. Can you give me an example to demonstrate how it is done?:( (1 Reply)
Discussion started by: xerox
1 Replies

7. UNIX for Dummies Questions & Answers

bash script & sql query

Hi Guys, I would like with this script "DATA=`ora123 su -c 'echo "SET HEADING OFF;\n SET FEED OFF;\n select USER NAME, ACCOUNT_STATUS from dba_users;\n exit" | sqlplus / as sysdba -s /' ` echo $DATA >> $DAT" make a sql query, but the statement "select USER NAME, ACCOUNT_STATUS from... (6 Replies)
Discussion started by: ixibits
6 Replies

8. Shell Programming and Scripting

Connecting to MS SQL database from bash (using unixODBC)

I've installed unixODBC and I would like to connect to a MS SQL (2005) database from a bash script. Can you post a code example? Thank you! :D J. (0 Replies)
Discussion started by: ph0enix
0 Replies

9. Programming

about wave file integrating.

Now I have two wave file(*.wav) at Tru64 Unix machine. I want to make a new wave file including the two wave file. how I should finish this programmer. If you know, can you give me the format of the wave file(*.wav) and Sun au file(*.au). Thank you. (1 Reply)
Discussion started by: livic
1 Replies
Login or Register to Ask a Question