Visit Our UNIX and Linux User Community

Top Forums Shell Programming and Scripting How to get df output into MySQL using bash? Post 302435966 by radoulov on Thursday 8th of July 2010 04:54:38 PM
Old 07-08-2010
You could try something like this:

- assuming a table structure like this:

create table df (
  hostname varchar(50),
  filesystem varchar(100),
  blocks int,
  used int,
  available int,
  capacity varchar(4),
  mounted varchar(100),
  ts timestamp default current_timestamp 

- assuming paths with no white space characters:

df -Pk | awk 'NR > 1 { 
  $1 = $1; printf "insert into df values ( \47%s\47,", h 
  for (i = 0; ++i <=NF;)
    printf "\47%s\47,", $i
  print " current_timestamp );"     
  }' OFS=, h="$(hostname)" | 
  mysql -u <username> -p<password> <db_name>

These 2 Users Gave Thanks to radoulov For This Post:
Test Your Knowledge in Computers #68
Difficulty: Easy
Awk is abbreviated from the names of the developers - Aho, Weinberger, and Kernighan.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing a MySql password from bash script

Hi all, I am running this script on Mandrakelinux release 10.1, #1 SMP I have also installed 'expect' separately. I have created an Rsync script, but before any Rsync command does run, a MySql dump must be done first, and I am battling a bit to pass the MySql password from... (2 Replies)
Discussion started by: codenjanod
2 Replies

2. Shell Programming and Scripting

bash mysql export to file

I'm trying to export a mysql query to a .csv file, right now I'm running a successful query like: us_id=`mysql -u $USER_NAME --password=$PASSWORD -D "databasename" \ -e "SELECT * \ FROM databasename.table \ WHERE somefield >0 AND otherfield ='$ctry' \ ORDER BY... (1 Reply)
Discussion started by: unclecameron
1 Replies

3. Shell Programming and Scripting

mysql and bash...

Ok the issue I have is a bit complicated, for me, and my understanding of shell programming and bash is non-existent. Background: I do web development for a team of programmers that make custom kernels for the Android OS. The guys are using a bash script (through gerrit or github, like I said... (4 Replies)
Discussion started by: Nyght
4 Replies

4. Shell Programming and Scripting

How to run bash script from within MySQL

Can someone tell me the syntax to run a shell script from within MySQL? I know there is a way to do it, but I can't remember the syntax. I thought it was something like: mysql> \. /user/myscript; but I get this error: Failed to open file '/user/myscript;', error: 2 Please help!... (4 Replies)
Discussion started by: peterv6
4 Replies

5. Programming

Loop in bash file for mysql

Hi, I'm having problems with a script which some of you helped me with last week. It's a script to check the status of orders in an SQL database, and if the count(*) is zero, then the script stops. If it's non-zero, the script echos the result to a file and then in cron, I cat the file and mail... (3 Replies)
Discussion started by: davidm123SED
3 Replies

6. Shell Programming and Scripting

[BASH] Gawk + MYSQL script

Hello! I've got script to write. It should read databases (names, volumes) from table testdatabase and compares it to actually existing databases in /var/lib/mysql/. If there is no informations about database in table - we should see information "There is no declared informations about database... (1 Reply)
Discussion started by: Zimny
1 Replies

7. UNIX and Linux Applications

Mysql erratic output

Hi,this doesnt give any output mysql -uroot -phruti2 -B -e "use WebNmsDB;select HEADERINDEX from meas_headers where CLLI= '$clli' and IVALSTART>'$ivalstart' and IVALSTART<'$ivalend' and RPTTYPE='$rpttype';" > asdf.txt This generates "good" output mysql -uroot -phruti2 -B -e "use... (1 Reply)
Discussion started by: leghorn
1 Replies

8. Shell Programming and Scripting

Technical questions on bash,mysql and pHp

1. bash -bash escape rules, esp. ',", -how to use Ctrl+R reverse cmd search with regex? 2. mysql -how to use grep in mysql 3. php -why !0 is not evaluated to true? what's its value -php getopt: what if there is duplicate in cmdline args (2 Replies)
Discussion started by: John_Peter
2 Replies

9. Shell Programming and Scripting

Conditional bash/mysql query help

I think(hope) I've got a simple one - I just need to send an email if a mysql query returns any results (ideally - it will never match). Currently I just pipe the mysql query output to the mail program, but of course that emails regardless of the output( and I check this every 10 minutes from... (5 Replies)
Discussion started by: jcass78
5 Replies

10. Shell Programming and Scripting

Mysql output to file

Hi, Below is my code to execute mysql statement , how to save the output to a file ? #!/usr/bin/bash #Script to run automated sql queries #Declaring mysql DB connection MASTER_DB_USER='root' MASTER_DB_PASSWD='root' MASTER_DB_PORT=3306 MASTER_DB_HOST='localhost'... (1 Reply)
Discussion started by: Pratik4891
1 Replies
mysqmail-postfix-logger(8)				      System Manager's Manual					mysqmail-postfix-logger(8)

mysqmail-postfix-logger - logs smtp traffic to a mysql database SYNOPSIS
mysqmail-postfix-logger subprogram [ args ... ] DESCRIPTION
mysqmail-postfix-logger reads the syslog using tail -F and for each lines, does an action in a selected table in the selected mysql server (configuration done using /etc/mysqmail.conf). All messages that have been delivered are marqued as so in the from and in the to field of the smtp traffic table. mysqmail-postfix-logger uses a table corresponding to this one: CREATE TABLE IF NOT EXISTS smtp_logs ( id int(11) NOT NULL auto_increment, newmsg_id bigint(20) default NULL, bounce_qp int(11) default NULL, bytes int(11) NOT NULL default '0', sender_user varchar(128) NOT NULL default '', sender_domain varchar(128) NOT NULL default '', delivery_id bigint(20) default NULL, delivery_user varchar(128) NOT NULL default '', delivery_domain varchar(128) NOT NULL default '', delivery_success enum('yes','no') NOT NULL default 'no', time_stamp timestamp(14) NOT NULL, PRIMARY KEY (id), UNIQUE KEY bounce_qp (bounce_qp), UNIQUE KEY newmsg_id (newmsg_id), KEY sender_domain (sender_domain), KEY delivery_domain (delivery_domain) ) TYPE=MyISAM; VERSION
This documentation describes mysqmail-postfix-logger version 0.1.4. See for updates. SEE ALSO
syslog(3), logger(8) mysqmail-postfix-logger(8)

Featured Tech Videos

All times are GMT -4. The time now is 12:38 AM.
Unix & Linux Forums Content Copyright 1993-2021. All Rights Reserved.
Privacy Policy