TA的每日心情 | 慵懒 2024-1-24 14:08 |
---|
签到天数: 313 天 [LV.8]以坛为家I
08:00大乘期
- 积分
- 6011
|
本帖最后由 xiaoke 于 2019-8-29 18:27 编辑
- //echo "# Let NetworkManager manage all devices on this system:" >/etc/netplan/test.yaml
- cmd1="sudo echo "# Let NetworkManager manage all devices on this system:" >";// 描述信息
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- cmd1="sudo sed -i '$a network:' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- cmd1="sudo sed -i '$a version: 2' ";// 本版信息
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
-
- cmd1="sudo sed -i '$a renderer: NetworkManager' ";// 管理信息
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- cmd1="sudo sed -i '$a ethernets:' ";// 修改网卡信息
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- cmd1="sudo sed -i '3,$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- int num = 0;
- int nrow = 5;
- for(int i=0;i<m_netinfos.size();i++)
- {
-
- cmd1="sudo sed -i '$a ";
- cmd1 += m_netinfos.strName;
- cmd1+=":\' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
- //std::string strNum=lexical_cast<string>(num*3+6);
- ostringstream ostr;
- //ostr<<(num*6+6);
- ostr<<((int)nrow);
- std::string strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- if(m_netinfos.strDhcp4!="")// DHCP
- {
- cmd1="sudo sed -i '$a dhcp4: ";
- cmd1 += m_netinfos.strDhcp4;
- cmd1 += "\' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
- ostr.str("");
- //ostr<<(num*6+6+1);
- ostr<<((int)nrow);
- strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- }
- if(m_netinfos.strIp!="")
- {
- ostr.str("");// ip/掩码
- ostr<<(netmask_str2len(m_netinfos.strSubMask.c_str()));
- strNum=ostr.str();
- cmd1="sudo sed -i '$a addresses: [";
- cmd1 += m_netinfos.strIp;
- cmd1 += "/"+strNum+"]\' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
- ostr.str("");
- //ostr<<(num*6+6+1);
- ostr<<((int)nrow);
- strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- }
- if(m_netinfos.strgateway!="")// gateway4
- {
- cmd1="sudo sed -i \'$a gateway4: ";
- cmd1+=m_netinfos.strgateway;
- cmd1+="\' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
- ostr.str("");
- //ostr<<(num*6+6+1);
- ostr<<((int)nrow);
- strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- }
- if(m_netinfos.strDns!="")// // DNS
- {
- cmd1="sudo sed -i '$a nameservers:' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
- //strNum=lexical_cast<string>(num*3+6+1);
- ostr.str("");
- //ostr<<(num*6+6+1);
- ostr<<((int)nrow);
- strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
-
- cmd1="sudo sed -i '$a addresses: [";
- cmd1 += m_netinfos.strDns;
- cmd1 += "]\' ";
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- nrow=nrow+1;
-
- ostr.str("");
- //ostr<<(num*6+6+5);
- ostr<<((int)nrow);
- strNum=ostr.str();
- cmd1="sudo sed -i '";
- cmd1 +=strNum;
- cmd1 +=",$s/^/ /g' ";// 插入空格
- cmd1 += filepath;
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
- }
- //num++;
- }
- cmd1="sudo netplan apply"; // 执行生效
- r = this->SystemCommand(cmd1, value);
- printf("SystemCommand: cmd1=%s -------xiaoke\n", cmd1.c_str());
复制代码
|
|