【发布时间】:2019-10-16 16:56:13
【问题描述】:
这是一个简单的脚本,可以将主机名更改为计算机序列号,以便于跟踪。但是,我们需要它在关机或重启时运行。调用此方法的最佳方法是什么。
#!/usr/bin/env bash
# Get the Serial Number of the Machine
sn=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')
# Set the ComputerName, HostName and LocalHostName
scutil --set ComputerName $sn
scutil --set HostName $sn
scutil --set LocalHostName $sn
fi
【问题讨论】:
-
您可以编写您的
bash脚本 -- 在您的crontab中,您可以输入以下代码:@reboot bash /path/to/bash/file-- 只要cron在重启期间在线,它就会运行该脚本..