lib/net/ssh/session_helpers.rb in net-ssh-session-0.1.3 vs lib/net/ssh/session_helpers.rb in net-ssh-session-0.1.4
- old
+ new
@@ -45,16 +45,23 @@
def directory_exists?(path)
run("test -d #{path}").success?
end
# Check if remote file exists
- # @param path [String] file path
+ # @param [String] file path
# @return [Boolean] execution result
def file_exists?(path)
run("test -f #{path}").success?
end
+ # Check if a symbilic link exists
+ # @param [String] file path
+ # @return [Boolean]
+ def symlink_exists?(path)
+ run("test -h #{path}").success?
+ end
+
# Check if process with PID is running
# @param pid [String] process id
# @return [Boolean] execution result
def process_exists?(pid)
run("ps -p #{pid}").success?
@@ -65,9 +72,23 @@
# @param signal [String] signal to send
# @return [Boolean] exection result
def kill_process(pid, signal='SIGTERM')
run("kill -#{signal} #{pid}")
process_exists?(pid)
+ end
+
+ # Check if user exists
+ # @param [String] username
+ # @return [Boolean]
+ def has_user?(name, options={})
+ run("id #{name}").success?
+ end
+
+ # Check if group exists
+ # @param [String] group name
+ # @return [Boolean]
+ def has_group?(name)
+ run("id -g #{name}").success?
end
# Export an environment variable
# @param key [String] variable name
# @param value [String] variable value
\ No newline at end of file