nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

text output to mysql

This is a discussion on text output to mysql within the Shell scripting forums, part of the Development/Scripting category; Dear all, I wonder if someone can help me. On a linux server (RHEL) I collect different output file from ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-16-2007, 10:26 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: fedora
Posts: 4
Rep Power: 0
chebbab is on a distinguished road
Exclamation text output to mysql

Dear all,

I wonder if someone can help me.
On a linux server (RHEL) I collect different output file from different informations.
these files I want to dump into a mysql db so I can create a php script that generate a reporting on the intranet.
this should all happen automatically via crontab.

Can someone help me please

thanks a lot
chebbab
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-18-2007, 08:26 AM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 481
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

use mysql -e 'sql-command1;sql-command2;' syntax for shell script to dump infomation from a shell script.
for example
Code:
#!/bin/bash
file="/tmp/output.$$"
cat /proc/cpu >$file
mysql -u user -p password db-name -e "sql-command to dump data from $file"
/bin/rm -rf $file
Above is just an example now a working code but it should be used as starting point you can call about script from a crontab

On a related note I recommend php for all sort of work for getting input from system to dumping data to generating reports. PHP can work from a shell and cron
__________________
May the force with you!
Reply With Quote
  #3 (permalink)  
Old 11-18-2007, 11:15 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: fedora
Posts: 4
Rep Power: 0
chebbab is on a distinguished road
Default

Hi Monk,

Thanks for the reply.

just little question, what about the output file containing alle the gathered data, in which format should it be. do I need to put all data with a seperator?

greets
chebbab
Reply With Quote
  #4 (permalink)  
Old 11-21-2007, 02:46 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: fedora
Posts: 4
Rep Power: 0
chebbab is on a distinguished road
Default

Hi my latest question I managed to find the solution

tail -1 file | cut -d= -f3 -f6 -f8 -f10 -f12 >> file.out

touch file.tmp
(for text in `cat file.out`;
do
echo -e -n " \b$text " >> file.tmp
done

cat file.tmp | tr [:blank:] , >> file.csv

Now this works and I got all my needed data into a comma seperated file.
I also tried the above received code from you Monk but I don't understand what it realy does, where does my .CSV file fits?

these file need to be dumped into a mysql db in a table..

thanks for your help
Reply With Quote
  #5 (permalink)  
Old 11-26-2007, 07:29 PM
Junior Member
User
 
Join Date: Nov 2007
My distro: fedora
Posts: 4
Rep Power: 0
chebbab is on a distinguished road
Default

Dear All,

In the meantime I'm using the above code to generate a file with all the necessary info I need and comma seperated.

Now what I need is that a file is generated with the following conntent already

insert into 'mytable' values (my comma seperated info generated from the previous script;

example

insert into 'mytable' values (1,2,3,4);

Who can help me out please
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
To find and replace in text file nashtech Shell scripting 3 07-31-2008 06:46 PM
need to convert text files into mysql database zafar466 Databases servers 2 07-12-2008 12:31 PM
rearranging columns in a text file sureshbup Shell scripting 2 12-06-2006 09:43 AM
Appending text files sparky Shell scripting 13 04-03-2006 04:43 PM
Replacing text in a file using awk postyrus Shell scripting 4 05-02-2005 03:31 PM


All times are GMT +5.5. The time now is 12:35 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36