How to execute script after system reboot by using kickstart

7.9k views Asked by At

I'm using PXE to install ISO. There are two scripts for environment configuration, I want to added them in kickstart file, so the environment will be setup completely and automatically after the system installed.

However, my situation is:

  1. Script 1 must reboot (has been added in script1.sh)
  2. Script 2 depends on script 1

Here part of kickstart file:

...
...
%post

wget http://xxx/script1.sh
wget http://xxx/script2.sh

sh -x script1.sh | tee script1.log
sh -x script2.sh | tee script2.log

%end

So, is there anyway that script 2 can be executed after system reboot by using kickstart file? Or the other way, just executed the script 2 once after reboot.

Thanks.

1

There are 1 answers

2
Nigel Tufnel On BEST ANSWER

The way I have done this is to make a startup script that calls secondary script(s), which in your case are script1.sh and script2.sh.

Here is one reference about configuring RHEL 6 Runlevels and Services. Alternatively, if have access to an existing RHEL/CentOS system you could browse /etc/init.d/ and copy one of the simpler startup scripts there as the basis for your own.

To put this all together, you'll need to:

In your kickstart file

  1. Add an additional wget call to download the startup script you created.
  2. You'll need to copy/move the startup script to /etc/init.d . Keep in mind that %post is run in a chroot environment.
  3. Enable the startup script on boot with chkconfig.

In your startup script

  1. Upon successful completion of script2.sh, disable the startup script with another chkconfig *service_name* off so it isn't run on future reboots.