# executing script as last thing after boot or reboot

**URL:** <https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631>\
**Category:** SLES Configure-Administer\
**Created:** [November 17, 2015, 6:51pm UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631 "2015-11-17T18:51:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron7000](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@ron7000](https://forums.suse.com/u/ron7000)\
**Post date:** [November 17, 2015, 6:51pm UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/1 "2015-11-17T18:51:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ron7000](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@ron7000](https://forums.suse.com/u/ron7000)\
**Post date:** [November 17, 2015, 9:07pm UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/2 "2015-11-17T21:07:02Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [November 17, 2015, 11:23pm UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/3 "2015-11-17T23:23:02Z")

</div>

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 😉

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

---

<div class="post-metadata">

**Author:** ![ron7000](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@ron7000](https://forums.suse.com/u/ron7000)\
**Post date:** [November 18, 2015, 7:01am UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/4 "2015-11-18T07:01:08Z")

</div>

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

```auto
#!/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.

---

<div class="post-metadata">

**Author:** ![ron7000](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@ron7000](https://forums.suse.com/u/ron7000)\
**Post date:** [November 18, 2015, 7:19am UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/5 "2015-11-18T07:19:25Z")

</div>

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

```auto

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

/bin/su -c whoami ron2

```

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

```auto
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
```

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [November 18, 2015, 11:27am UTC](https://forums.suse.com/t/executing-script-as-last-thing-after-boot-or-reboot/27631/6 "2015-11-18T11:27:03Z")

</div>

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 😉 )

Regards,  
Jens
