Class: DevopsSystemUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/devops_system_util_profiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir_path, backup_dir_path, file_extension) ⇒ DevopsSystemUtil

Returns a new instance of DevopsSystemUtil.



2
3
4
5
6
# File 'lib/devops_system_util_profiler.rb', line 2

def initialize(dir_path, backup_dir_path, file_extension)
    @dir_path = dir_path
    @backup_dir = backup_dir_path
    @extension = file_extension 
end

Instance Method Details

#changepermission(directory_path) ⇒ Object



27
28
29
30
# File 'lib/devops_system_util_profiler.rb', line 27

def changepermission(directory_path)
    @directory = directory_path
    exec("sudo chown -R $(whoami) @directory")
end

#checksystemversionObject



31
32
33
# File 'lib/devops_system_util_profiler.rb', line 31

def checksystemversion
    return `sh --version`
end

#directorycheckObject



34
35
36
# File 'lib/devops_system_util_profiler.rb', line 34

def directorycheck
    return `ls -la`.split("\n")
end

#filesearch(dir_path, file_extension) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/devops_system_util_profiler.rb', line 37

def filesearch(dir_path,file_extension)
    @dir = Dir.open(dir_path)
    @file_ext = file_extension
    file_list = Array.new()
    @dir.each{|each| file_list.push(each) if each.end_with?(@file_ext)}
    return file_list
end

#geneatepathObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/devops_system_util_profiler.rb', line 7

def geneatepath
    dir_storage = Dir.open(@dir_path)
    dir_path = @backup_dir.to_s
    file_storage_copy = dir_storage.each{|each| \
                puts "cp -r " + each + " " + dir_path + "/" + "backup" + each \
                                        if each.end_with?(@extension)}
    file_storage_move = dir_storage.each{|each| \
                puts "mv " + each + " " + dir_path + " " + "backup" + each \
                                        if each.end_with?(@extension)}
     return file_storage_copy, file_storage_move
end

#generate_push_ssh(dir_path, file_extension, remote_server, remote_address) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/devops_system_util_profiler.rb', line 44

def generate_push_ssh(dir_path, file_extension, remote_server, remote_address)
    dir_string = dir_path
    @dir = Dir.open(dir_path)
    @file = file_extension
    @remote = remote_server
    @remote_add = remote_address
    generating_path = Array.new()
    @dir.each{|each| generating_path.push(dir_string + each) if each.end_with?(@file)}
    generating_path.map{ |n| "scp -r" + " " + n + " " + @remote + ":" + @remote_add}.each{ |each| puts each}
end

#getsystemInfoObject



18
19
20
# File 'lib/devops_system_util_profiler.rb', line 18

def getsystemInfo
    return `uname -a`.to_s
end

#memoryObject



21
22
23
# File 'lib/devops_system_util_profiler.rb', line 21

def memory
    return `memory_pressure`.split("\n")
end

#userObject



24
25
26
# File 'lib/devops_system_util_profiler.rb', line 24

def user
    return `whoami`.to_s
end