title: Create a symlink using ruby
body: <p>I am trying to create a symlink for the created file but I get an error like <code>File exists - (/etc/nginx/sites-available/sushant.com, /etc/nginx/sites-enabled/sushant.com) (Errno::EEXIST)</code> </p>
  
  <p>Here is my code</p>
  
  <pre><code>    require 'fileutils'
  open('/etc/hosts') do |f|
    matches = []
    vhosts = []
    f.readlines.each do |lines|
      matches &lt;&lt; lines if lines =~ /.*.com/
    end
    matches.each do |val|
      val.split.each do |x|
        vhosts &lt;&lt; x if x =~ /.*.com/
      end
    end
    vhosts.each do |domain|
  #put the path to sites-enabled
      unless File.file? "/etc/nginx/sites-available/#{domain}"
        open("/etc/nginx/sites-available/#{domain}", 'w') do |g|
          g &lt;&lt; "server { \n"
          g &lt;&lt; "\tlisten 80 default_server;\n"
          g &lt;&lt; "\tlisten [::]:80 default_server ipv6only=on;\n"
          g &lt;&lt; "\troot /usr/share/nginx/html;\n"
          g &lt;&lt; "\tindex index.html index.htm;\n"
          g &lt;&lt; "\tserver_name localhost;\n"
          g &lt;&lt; "\tlocation / {\n"
          g &lt;&lt; "\t\ttry_files $uri $uri/ =404;\n"
          g &lt;&lt; "\t}\n"
          g &lt;&lt; "}\n"
          g &lt;&lt; "server {\n"
          g &lt;&lt; "\tpassenger_ruby /path/to/ruby;\n"
          g &lt;&lt; "\trails_env development;\n"
          g &lt;&lt; "\tlisten 80;\n"
          g &lt;&lt; "\tserver_name #{domain};\n"
          g &lt;&lt; "\troot /usr/share/nginx/html/#{domain}/public;\n"
          g &lt;&lt; "\tpassenger_enabled on;\n"
          g &lt;&lt; "}\n"
        end
        File.symlink  "/etc/nginx/sites-available/#{domain}", "/etc/nginx/sites-enabled/#{domain}"
      end
    end
  
    p vhosts
  end
  </code></pre>
  
  <p>Why is the EEXIST error occurs after I run the script? Am I missing out on something?</p>