         tables_sql: tables_sql
     )
     
+    if typeof config.ssh_host is "undefined"
+      grunt.log.oklns "Getting prefix matches in LOCAL db/prefix ['" + config.database + "'/'" + config.table_prefix + "']"
+    else
+      grunt.log.oklns "Getting prefix matches in REMOTE db/prefix ['" + config.database + "'/'" + config.table_prefix + "']"
+      tpl_ssh = grunt.template.process(tpls.ssh,
+        data:
+          host: config.ssh_host
+      )
+      prefix_matches_cmd = tpl_ssh + " \"" + prefix_matches_cmd.replace( /\"/g, '\\"' ) + "\""
+
     # console.log('cmd \n' + prefix_matches_cmd);
     prefix_matches = shell.exec(prefix_matches_cmd,
       silent: true
-    ).output.replace(/(\r\n|\n|\r)/g, "")
-    
-    # console.log('matches [' + prefix_matches +']');
+    ).output
+
+    # Make sure to remove 'stdin: is not a tty' if that error appears
+    # Fix : On the destination server, edit /etc/bashrc file and comment out the "mesg y" line.
+    # http://www.linux.org/threads/stdin-is-not-a-tty.16/?codekitCB=415084070.551448
+    prefix_matches = prefix_matches.replace(/stdin: is not a tty/g, "")
+
+    # Remove new lines/return chars
+    prefix_matches = prefix_matches.replace(/(\r\n|\n|\r)/g, "")
+    
+    # console.log prefix_matches
+
     prefix_matches.split " "
 
   

        host: config.host
    )
    if typeof config.ssh_host is "undefined"
      grunt.log.oklns "Creating DUMP of local database [" + config.database + "]"
    else
      grunt.log.oklns "Creating DUMP of remote database"
      tpl_ssh = grunt.template.process(tpls.ssh,
        data:
          host: config.ssh_host

        sql_connect: sql_connect
        sql: sql
    )

    
    cmd = exports.add_ssh_connect config, cmd if config.ssh_host?

    console.log "tables to dump cmd \n" + cmd

    # Make sure you strip the new line chars
    tables_to_dump = shell.exec(cmd,
      silent: true
    ).output

    console.log "tables_to_dump\n" + tables_to_dump

    tables_to_dump.replace(/(\r\n|\n|\r)/g, "")
    tables_to_dump.split " "

  
  # Run the mysqldump cmd and append the table names from exports.tables_to_dump() fn
  exports.prefixed_sqldump = (config, tables_to_dump) ->
    return false  unless tables_to_dump
    cmd = exports.mysqldump_cmd(config) + " " + tables_to_dump.join(" ")

    if typeof config.ssh_host is "undefined"
      grunt.log.oklns "Creating prefixed DUMP of local database [" + config.database + "/" + config.table_prefix + "]"
    else
      grunt.log.oklns "Creating prefixed DUMP of remote database [" + config.database + "/" + config.table_prefix + "]"
      # tpl_ssh = grunt.template.process(tpls.ssh,
      #   data:
      #     host: config.ssh_host
      # )
      # cmd = tpl_ssh + " \"" + cmd + "\""

    console.log "prefixed sqldump cmd\n" + cmd
    cmd
  
  exports.add_ssh_connect = ( config, cmd ) ->
    tpl_ssh = grunt.template.process(tpls.ssh,
      data:
        host: config.ssh_host
    )
    cmd = tpl_ssh + " " + cmd
    console.log cmd, 'add ssh connect'
    cmd

  #==========  Caliper mods  ==========


  exports.db_import = (config, src) ->
    shell.exec exports.mysql_cmd(config, src)
    grunt.log.oklns "Database imported succesfully"
