You are not logged in.

#1 2013-11-12 19:36:39

studentik
Member
Registered: 2013-05-24
Posts: 38

[SOLVED] SELECT * FROM... linux commands that return table data

There are many commands in linux that output table-structured information, such as ls, ps, lsblk, lsof etc... Is there any generic way to send output of such commands directly to some relational database to manipulate this data via SQL?

Even more, is there a way to access somehow /sys and /proc data via SQL?


Something like
SELECT * FROM linux.processess WHERE user='root'
or
SELECT * FROM linux.block_devices WHERE fstype='ext4'

Last edited by studentik (2013-11-23 23:10:05)

Offline

#2 2013-11-12 20:04:10

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] SELECT * FROM... linux commands that return table data

If you're lucky, grep will do it :-)

Offline

#3 2013-11-12 20:06:18

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: [SOLVED] SELECT * FROM... linux commands that return table data

karol wrote:

If you're lucky, grep will do it :-)

Even JOIN and GROUP BY? smile

Offline

#4 2013-11-12 20:12:46

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] SELECT * FROM... linux commands that return table data

Maybe awk then? perl?

AFAIK, text output is the glue of FLOSS programs. You can parse it, slice and dice it anyway you need.
Often they have handy command options that do just what you need, but I don't think there's any universal format.

Offline

#5 2013-11-12 20:39:11

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: [SOLVED] SELECT * FROM... linux commands that return table data

karol wrote:

Maybe awk then? perl?

Sorry if I sound like troll, but after some experience with databases, everything looks like data structure. It seems wrong when every command has it's own language to CRUD its table data.

Is there any movement in linux towards normalization/unification of manipulating it's data in a relational manner? Do such projects/ideas even exist?

Offline

#6 2013-11-12 20:56:17

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] SELECT * FROM... linux commands that return table data

systemd with its binary journal http://www.freedesktop.org/wiki/Softwar … nal-files/ is not a relational db AFAICT, but it provides some unification.
Historically, applications were meant to do one thing, and do it well. They output text which you can transform using powerful tools with a wide array of options, like 'sed', 'grep' or 'awk'. You have more specialized tools like 'paste' or 'join' too.

Offline

#7 2013-11-22 04:39:08

causasui
Member
Registered: 2013-04-04
Posts: 63

Re: [SOLVED] SELECT * FROM... linux commands that return table data

studentik wrote:

Is there any generic way to send output of such commands directly to some relational database to manipulate this data via SQL?

This question is not well formed: there cannot be any "generic" way to pipe output from stdout into "some relational database", because each RDBMS is unique. Furthermore, blindly piping a single column of plain text into a relational database is pointless since stdout is, by definition, non-relational. An RDBMS with nothing but a text column would have no advantage over a plain-text file. In a relational model, a developer defines the schema.

Therefore you must, categorically and in every case, have:

(a) an RDBMS with a defined schema suitable to the application
(b) some logical layer or wrapper that transforms the output of your shell app into legal SQL that your server can understand. That obtains for apps that print to stdout in regular formats like xml or json: you still have to transform that into an INSERT or it ain't going into any relational database.

Without that, you're not doing any work.

Last edited by causasui (2013-11-22 04:39:57)

Offline

#8 2013-11-22 05:23:46

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: [SOLVED] SELECT * FROM... linux commands that return table data

studentik wrote:

Sorry if I sound like troll, but after some experience with databases, everything looks like data structure. It seems wrong when every command has it's own language to CRUD its table data.

A96LEGys.jpg
If all you have is a hammer, everything looks like a nail neutral

Offline

#9 2013-11-22 06:42:49

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: [SOLVED] SELECT * FROM... linux commands that return table data

causasui wrote:

there cannot be any "generic" way to pipe output from stdout into "some relational database", because each RDBMS is unique

Obviously, I meant not just sending text output into one field, but parsing known formatted output into prepared table structure.

I was hoping that someone already solved this problem and there is a suitable tool for that. But if no, then nothing stops me from making it and sharing with community.

Offline

#10 2013-11-23 23:09:49

studentik
Member
Registered: 2013-05-24
Posts: 38

Re: [SOLVED] SELECT * FROM... linux commands that return table data

SOLVED: sysql

Offline

Board footer

Powered by FluxBB