Hi All,
I want to run some commands and get the output into a mysql database.
I want to run the df cmd into a text file, then import it into my db sysinfo using a bash script.
My table "df" has the following 9 fields:
server, filesystem, size, used, available, useperc, mounted, date, time
cmd for df creates it in a comma separated output.
df -k | tr -s " " | sed 's/ /, /g' | grep -v Filesystem > df.txt
bash script for loading data:
#!/bin/bash
/usr/bin/mysql --user=<user> --password=<password> --database=sysinfo<<EOFMYSQL
load data local infile 'df.txt' INTO TABLE df fields terminated by '\,' LINES
TERMINATED BY '\n';
EOFMYSQL
Unfortunately this is not working and I only get the first line imported.
Can some one show me how to fix this script, I think it may be to do with the line terminators but can't find a solution.
I would also like to prepend the host name for field 1 and the date and time in the last 2 fields.
I'm very new to sql would really apreciate some help and advice.