1

Can i use mySQL from inside awk code

Basically i want the data AWKED in this post

into Mysql database

  • The short answer is "probably". The medium answer is that there's probably a better way to do what you want. The long answer depends on what you're trying to do. More detail in your questions and accepting and up-voting answers will help you in the long run. – Dennis Williamson May 03 '10 at 05:37
  • Changed my Post –  May 03 '10 at 06:40

2 Answers2

1

Based on the linked question it appears that you would like to log statistics obtained from rsync --stats, i.e. something like this:

Number of files: 4
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 66
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 80
Total bytes received: 13

sent 80 bytes  received 13 bytes  186.00 bytes/sec
total size is 0  speedup is 0.00

You could parse the interesting bits from that output with AWK and then output an appropriate SQL statement. Something like this:

#!/usr/bin/awk -f
/^Number of files: / {
    num_files = $4;
}
/^Number of files transferred: / {
    num_tranferred = $5;
}
/* etc... */
END {
  printf("INSERT INTO some_table (num_files, num_transferred) \                
         VALUES (%d, %d);\n", num_files, num_transferred);
}
jackem
  • 216
  • 1
  • 4
  • ...which you can then pipe into mysql; `rsync --blah blah blah | ./awk-script | mysql -ublah -hblah database` – James May 03 '10 at 10:28
0

You're probably trying to use a hammer with a screw here :) You definitely should use a language like Perl, Python or Ruby for this. It will be much faster, and more solid. Even PHP would be better, actually :)

wazoox
  • 6,918
  • 4
  • 31
  • 63