I have similar need, I want to know if a file/directory exists on a
remote server and do different things as a result.
The below seems to work, but wondering if there is a better way to do
this:

If I try to do a run "ls -l #{file}", it will throw an error and then
you have to surround it with a begin/rescue/end block, which seems
even  uglier...

# assumes you are using keys that do not require passwords, etc
def remote_exists?(host, file)
  system("ssh #{host} test -e #{file}")
end

task :deploy_mail do
  host = roles[:app][0].host  # seems a bit of a hack and has problems
if role has many servers...
  puts "result=" << remote_exists?(host, "/etc/mail/smrsh").to_s
end

Comments?

On Jan 6, 1:15 pm, RubySmith <[EMAIL PROTECTED]> wrote:
>  delete a golden file on the server when failure happens. ( Make sure
> you copy the file from a known location before the start of the task.)
> You can even seperate concerns by using new before feature in Cap2. I
> love Cap when it comes to deployment and automation.
>  Then look for it using the following command.
> run "ls -l filename"
>
> If the file is not found the error code returned is 1. I have used
> this value build error checking and report failure in an automated
> way.
>
> -RS
>
> On Jan 4, 5:07 pm, RubySmith <[EMAIL PROTECTED]> wrote:
>
> > How can i test whether a file exist on aremoteserver within
> > Capistrano script and based on the result, i should raise an exception
> > or not?
>
> > File.exists?(remote_path) only work for locally. How can make it work
> > or run orremoteserver?
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to