创建 /lib/systemd/system/rc.local.service

  1. # This file is part of systemd.
  2. #
  3. # systemd is free software; you can redistribute it and/or modify it
  4. # under the terms of the GNU Lesser General Public License as published by
  5. # the Free Software Foundation; either version 2.1 of the License, or
  6. # (at your option) any later version.
  7. # This unit gets pulled automatically into multi-user.target by
  8. # systemd-rc-local-generator if /etc/rc.local is executable.
  9. [Unit]
  10. Description=/etc/rc.local Compatibility
  11. ConditionFileIsExecutable=/etc/rc.local
  12. After=network.target
  13. [Service]
  14. Type=forking
  15. ExecStart=/etc/rc.local start
  16. TimeoutSec=0
  17. RemainAfterExit=yes
  18. [Install]
  19. WantedBy=multi-user.target
  20. Alias=rc-local.service

创建 /etc/rc.local (记得加权限:chmod +x /etc/rc.local)

#!/bin/bash
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# echo "你的密码" | sudo -S mkdir /mnt/123
mkdir /tmp/test
sh /home/userName/my.sh 
exit 0