#Function :修改文件中的内容
#
#Parameter :ssh->登录到服务器的ssh对象实例
# key->键,value->值,sign->标识(采用哪一种修改方式)
#
#return :无
def modify_file_command(ssh,key,value,sign)
if sign == 1
sshexec!(ssh,"sed -i 's#"+key+".*$#"+key+"="+value+"#g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 2
sshexec!(ssh,"sed -i 's/"+key+"=[0-9]*.[0-9]*.[0-9]*.[0-9]*/"+key+"="+value+"/g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 3
sshexec!(ssh,"sed -i 's#"+key+".$#"+key+"="+value+"#g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 4
sshexec!(ssh,"sed -i 's/"+key+"=[0-9]*/"+key+"="+value+"/g' "+@CONFIGURATION_FILE_PATH)
end
end
注:其中 @CONFIGURATION_FILE_PATH="/opt/tools/configuration/configuration.conf"
为文件的绝对路径
#
#Parameter :ssh->登录到服务器的ssh对象实例
# key->键,value->值,sign->标识(采用哪一种修改方式)
#
#return :无
def modify_file_command(ssh,key,value,sign)
if sign == 1
sshexec!(ssh,"sed -i 's#"+key+".*$#"+key+"="+value+"#g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 2
sshexec!(ssh,"sed -i 's/"+key+"=[0-9]*.[0-9]*.[0-9]*.[0-9]*/"+key+"="+value+"/g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 3
sshexec!(ssh,"sed -i 's#"+key+".$#"+key+"="+value+"#g' "+@CONFIGURATION_FILE_PATH)
elsif sign == 4
sshexec!(ssh,"sed -i 's/"+key+"=[0-9]*/"+key+"="+value+"/g' "+@CONFIGURATION_FILE_PATH)
end
end
注:其中 @CONFIGURATION_FILE_PATH="/opt/tools/configuration/configuration.conf"
为文件的绝对路径