rc.localに書けばおけ。
あとCentOS7以上の場合だと、rootに実行権限をつけなきゃダメっぽいかも。

[root@KVM ~]# vi /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
echo aaa > /tmp/aaa.txt  #実行したいコマンドやシェルを追記

rootへのx付与

[root@KVM ~]# chmod u+x /etc/rc.d/rc.local
[root@KVM ~]# ls -l /etc/rc.d/rc.local
-rwxr--r--. 1 root root 520 11月 29 03:40 /etc/rc.d/rc.local

<スポンサーリンク>

2 Comments

  1. ほかの方法として、crontabの時刻設定のところに、@rebootと記述してもOS起動時にコマンドやシェルの自動起動ができます。
    どの方法がいいのか、わからないですが。

    1. それは知らなかった、crontabでもできるのですね。ありがとうございます!
      crontabのほうが、スケジューリングの時系列わかりやすいので、そちらのほうがよさそうですね。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)