mac系统配置开机自动执行rc.local文件
在linux系统上,要配置开机启动项很简单,只要在/etc/rc.d/rc.local里面写上想要开机执行的命令就可以了。
但是在mac上不存在rc.local这个东西,所以这篇文章记录下如何在mac系统上设置开机启动。
1. 执行以下命令创建/Library/LaunchDaemons/localhost.rc.local.plist文件
sudo vim /Library/LaunchDaemons/localhost.rc.local.plist
2. copy以下内容到上面的文件里面
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>Label</key> <string>localhost.rc.local</string> <key>Disabled</key> <false/> <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <false/> <key>LaunchOnlyOnce</key> <true/> <key>ProgramArguments</key> <array> <string>/etc/rc.local</string> </array> </dict></plist>
3. 执行以下命令
sudo launchctl load -w ./localhost.rc.local.plist
4. 使用以下命令创建/etc/rc.local文件
sudo vim /etc/rc.local
5. 使用以下命令修改rc.local的权限,使该文件可执行
sudo chmod +x /etc/rc.local
6. 可以在rc.local文件里面写入以下命令测试是否生效
/sbin/ifconfig lo0 alias 127.0.0.2
7. 第6步写入文件后,使用ifconfig lo0 查看是否设置生效