executing script as last thing after boot or reboot

what and how is the best way to accomplish having a simple script execute once whenever the system boots?
This would be for a cold boot from a powered off state, or after a reboot or init 6.
And i would want the script to be the very last or as close to last thing that happens after boot/reboot.

my script is just a few lmgrd commands to kick off some flexlm licenses, or echo the date and time to a text file of my choosing.
ideally i would want the script to execute the lmgrd commands as some other user besides root.

is the best/only way to do this by setting up the link in /etc/init.d/rc5.d/ such as S90_myscript and
have it link to /etc/init.d/myscript and do a chkconfig --add /etc/init.d/myscript ?

I was hoping there was some .local file I could place a call to my script,
rather than editing a full blown service file for start/stop/restart and all that which i’ll never need.

p.s. I am not asking for any code to be written :rolleyes:

Hi ron7000,

[QUOTE=ron7000;30460]is the best/only way to do this by setting up the link in /etc/init.d/rc5.d/ such as S90_myscript and
have it link to /etc/init.d/myscript and do a chkconfig --add /etc/init.d/myscript ?

I was hoping there was some .local file I could place a call to my script,
rather than editing a full blown service file for start/stop/restart and all that which i’ll never need.

p.s. I am not asking for any code to be written :rolleyes:[/QUOTE]

but you’ll get some :wink:

From /etc/init.d/rc (which is handling start/stop of run levels):

[CODE]#

Start the user defined resource control script which

should be executed after runlevel is reached.

if test -f /etc/init.d/after.local ; then
echo -n "Master Resource Control: "
echo “Running /etc/init.d/after.local”
/bin/sh /etc/init.d/after.local
rc_status -v1 -r
splashtrigger “after.local”
fi[/CODE]

So you could put your code into /etc/init.d/after.local.

Regards,
Jens

I had come across after.local doing a web search and it was stated that,
“This is executing scripts just after the initial machine boot, not the end of the init boot process”
This statement had a date of 2012 though,

so here is my after.local file

#!/bin/bash

echo "ronron running after.local"
echo -n "whoami = "
whoami
echo "su to ron2"
su ron2
echo -n "whoami = "
whoami

date >> /tmp/after.local.time.txt

below is a cleaned up except from bottom of /var/log/boot.msg

[code]
Starting smartd done
Starting Firewall Initialization (phase 2 of 2) SuSEfirewall2: done

Master Resource Control: Running /etc/init.d/after.local
ronron running after.local
whoami = root
su to ron2
Warning: no access to tty (Inappropriate ioctl for device).
Thus no job control in this shell.
HOSTNAME: Undefined variable.
linux /> [/code]

so it seems like using /etc/init.d/after.local is exactly what i need.

still have to figure out how to not be root and use some other account to kick off the things i want to,
my use of the su command in the script did not work.

got it, needed to do this in /etc/init.d/after.local:


echo -n "su -c whoami ron2:  whoami = "

/bin/su -c whoami ron2

that produced the following in /var/log/boot.msg

Master Resource Control: Running /etc/init.d/after.local
ronron running after.local
whoami = root
su -c whoami ron2:  whoami = ron2
doneMaster Resource Control: runlevel 5 has been reached

Hi ron7000,

got it, needed to do this in /etc/init.d/after.local: […]

yes, I was about to reply that “su” will start a sub-shell and that only commands within that sub-shell are running in the changed security context. If you have more than a single command to execute, create a wrapper script and call that instead (instead of creating a long, long “-c” parameter).

Also, during boot the script is not running with a connected tty, hence the “Warning: no access to tty (Inappropriate ioctl for device).” message, as your original call to “su” tried to create an interactive shell (which is not meaningful without a tty :wink: )

Regards,
Jens