Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can i use mySQL from inside awk code

Basically i want the data AWKED in this post

into Mysql database

share|improve this question
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 3 '10 at 5:37
Changed my Post – John May 3 '10 at 6:40

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... */
  printf("INSERT INTO some_table (num_files, num_transferred) \                
         VALUES (%d, %d);\n", num_files, num_transferred);
share|improve this answer
...which you can then pipe into mysql; rsync --blah blah blah | ./awk-script | mysql -ublah -hblah database – James May 3 '10 at 10:28

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 :)

share|improve this answer
can i use rsync with php?? – John May 3 '10 at 13:55
Of course, you can execute whatever external program you want from a php script. – wazoox May 4 '10 at 16:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.