更改主机名bash脚本(Change hostname bash script)
我正在尝试将图像启动时的主机名更改为/ 24 - / 32 IPv4地址。 我想出了以下脚本,但HNAME仍为NULL:
#!/bin/sh echo "Changing hostname to IP-related" HNAME=ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d. -f4 | awk '{ print $1 }' echo "Proposed hostname is: $HNAME" echo hostname=$HNAME echo "The new hostname is $HOST_NAME" echo
I'm trying to change my hostname at startup of an image to the /24 - /32 IPv4 address. I've come up with the following script, but HNAME remains NULL:
#!/bin/sh echo "Changing hostname to IP-related" HNAME=ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | cut -d. -f4 | awk '{ print $1 }' echo "Proposed hostname is: $HNAME" echo hostname=$HNAME echo "The new hostname is $HOST_NAME" echo
原文:https://stackoverflow.com/questions/29153564
更新时间:2024-01-04 10:01
最满意答案
你可以像这样做一个简单的字符串替换:
(另外,我希望你确保你的数据库保存为SQL注入)
$site_id = 5; $url = 'http://www.sitename.com?id=$site_id'; //As an example from DB $url = str_replace('$site_id', $site_id, $url); header("Location: $url");
You can do a simple string replace like this:
(Also i hope you made sure that you are save against SQL Injection for your DB)
$site_id = 5; $url = 'http://www.sitename.com?id=$site_id'; //As an example from DB $url = str_replace('$site_id', $site_id, $url); header("Location: $url");
相关问答
更多-
int a; printf("%d\n", a); 未初始化的对象具有不确定的值。 访问未初始化的对象是未定义的行为。 如果您尝试打印其值,则可以打印2或42否则您的应用程序可能会崩溃。 int a; printf("%d\n", a); A uninitialized object has an indeterminate value. Accessing an uninitialized object is undefined behavior. If you try to print its va ...
-
jQuery在数据库中选择下拉列表时更改变量的值(jQuery change the value of a variable on dropdown select from database)[2022-07-12]
单击是选择框的错误事件,您可以为结果使用更改事件。 $(document).ready(function(){ $("#pln").change(function(){ $("#chpln").text("Plan: "+$(this).val()+" secs"); }); }); click is a wrong event for selection box you can utilize change event for your result. $(documen ... -
尝试使用eval()。 echo eval($my_field); 另外,请注意。 在数据库中存储PHP代码是一个可怕的想法。 Try using eval(). echo eval($my_field); Also, note. Storing PHP code in the database is a horrible idea.
-
随时更改数据库名称(Changing Database name on the go php)[2022-08-27]
通过在你的类的__construct()方法中设置私有属性来改变你分配私有属性的方式。 尽管我不推荐使用这个配置文件,但您可以使用此Symphony组件 。 这里有一个例子 。 另外一个使用作曲家的快速教程可能会帮助你 编辑: private function __construct() { $this->dbName = $_SESSION['dname']; parent::__construct($this->dbHost, $this->user, $this->pass, $thi ... -
需要一个输出变量(Need an output variable)[2023-04-25]
您可以创建一个表值变量,然后使用您选择的数据填充它。 You could create a table valued variable and then populate it with the data you selected. -
你可以像这样做一个简单的字符串替换: (另外,我希望你确保你的数据库保存为SQL注入) $site_id = 5; $url = 'http://www.sitename.com?id=$site_id'; //As an example from DB $url = str_replace('$site_id', $site_id, $url); header("Location: $url"); You can do a simple string replace like this: (Also ...
-
更改php数组输出(Changing the php array output)[2023-06-14]
更改 if(mysql_num_rows($query) > 1){ $this->result[$i][$key[$x]] = $r[$key[$x]]; }else if(mysql_num_rows($query) < 1){ $this->result = null; }else{ $this->result[$key[$x]] = $r[$key[$x]]; } 同 if(mysql_num_rows($query) >= 1){ $this->result[$i ... -
当我改变一个变量的值时,另一个变量也在变化(When i am changing the value of one variable another is also changing)[2022-11-16]
目前,您直接将data对象引用分配给contactRoleForTrace & $scope.contactRole ,所以发生在$scope.contactRole / data任何更改都会自动更新contactRoleForTrace变量,因为它们受限于相同的引用( data对象)。 您应该使用angular.copy来创建data对象的克隆,因此contactRoleForTrace & $scope.contactRole将指向不同的引用。 contactRoleForTrace = angular ... -
您需要使用strtotime()将数据转换为timestamp 。 date()需要第二个参数是一个timestamp值。 试用 - $dateRequired = date("Y-m-d", strtotime($dateRequired)); m / d / y或dmy格式的日期通过查看各个组件之间的分隔符来消除歧义:如果分隔符是斜线(/),则假定美国m / d / y; 而如果分隔符是破折号( - )或点(。),则假定欧洲的dmy格式。 You need to use strtotime() to ...
-
这里有几个问题。 首先,在函数checkavatar ,您将变量checkavatar重新分配给查询结果。 实际上,这会在第一次调用时破坏该功能。 由于CF的奇怪的范围规则,您需要在执行查询之前首先在函数中包含类似
的行。 我还建议不要将变量命名为与它所在的函数相同的东西。 你对函数的调用应该最终看起来像 因为该函数返回路径。 排除本地文件与文件的Web可访问路径之间的差异可能会有其他问题,但这 ...