Saturday, February 12, 2011

Capistrano and awk

I was trying to use the cap invoke pattern and couldn't get it to work with awk.

$ cap HOSTS=user@server invoke COMMAND="awk '/PORT/ {print $8}' /var/log/ftp.log"

Turns out you need to escape the $8. The correct form is:

$ cap HOSTS=user@server invoke COMMAND="awk '/PORT/ {print \$8}' /var/log/ftp.log"

Note the backslash before the dollar sign. Even though there are quotes, the $8 get's lost somewhere along the line.

In the first case cap output looks like this:
* executing "awk '/PORT/ {print }' /var/log/ftpd.log "

and in the second case:
* executing "awk '/PORT/ {print $8}' /var/log/ftpd.log "


Hope this helps!

Post a Comment