LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Place to put a certain script to be run at boot time. (https://www.linuxquestions.org/questions/slackware-14/place-to-put-a-certain-script-to-be-run-at-boot-time-4175420394/)

stf92 08-04-2012 06:56 PM

Place to put a certain script to be run at boot time.
 
Hi:

Where could I place the following script to make it execute each time I boot?:
Code:


#!/bin/bash
( sudo setsid /kbd_monitor /dev/input/event1 </dev/null &>/tmp/input.log & )

I want have it run system-wide. There are three choices that I know of:
(a) /etc/inittab
(b) /etc/profile
(c) /etc/rc.d/rc.local

I put it in profile with no effects. As to inittab I refrained from touching it. Perhaps rc.local?

Kernel 2.6.21.5
Slackware 12.0

damgar 08-04-2012 07:14 PM

Quote:

I A /etc/rc.d/rc.local (sh) Row 1 Col 1 6:13 Ctrl-K H for help
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.

From rc.local

schneidz 08-04-2012 07:17 PM

my bet would be on rc.local.

i usually add an entry in crontab like so:
Code:

@reboot /run/this/script

willysr 08-04-2012 07:31 PM

it would be best to use absolute path instead of relative path if you are going to put it on your rc.local

stf92 08-04-2012 08:11 PM

rc.local was my first choice, and it did nothing. 'ps -C kbd_monitor', as it is in /usr/bin/, shows it isn't running.

stf92 08-04-2012 08:13 PM

I did used the absolute path.

damgar 08-04-2012 08:42 PM

Did you remember to
Code:

chmod +x /etc/rc.d/rc.local
And I believe he means absolute path for the command such as /usr/bin/setsid instead of just setsid

Mark Pettit 08-05-2012 02:55 AM

You won't need the 'sudo' either, as rc.local will run as root on boot.

stf92 08-05-2012 03:13 AM

Thanks, I did not use the sudo, of course. But now, having put the full pathname of setsid, it starts after boot. Cool!

ottavio 08-06-2012 01:44 PM

Quote:

Originally Posted by schneidz (Post 4746102)
my bet would be on rc.local.

i usually add an entry in crontab like so:
Code:

@reboot /run/this/script

Isn't this deprecated? Or at least I thought all 'at' crontabs were.

schneidz 08-06-2012 01:46 PM

i never heard that but i think putting it in rc.local is more leet.

stf92 08-06-2012 02:08 PM

A little off-topic but there it goes: what should I do if I want a message written by me output to stdout just after boot to remind me a certain thing? I have tried several places but i'm defeated by the famous slack daily quotation! If it fills the screen then my message cant be read at first sight and anyways, I want it to be the very last thing printed.

T3slider 08-06-2012 05:39 PM

Quote:

Originally Posted by stf92 (Post 4747441)
A little off-topic but there it goes: what should I do if I want a message written by me output to stdout just after boot to remind me a certain thing? I have tried several places but i'm defeated by the famous slack daily quotation! If it fills the screen then my message cant be read at first sight and anyways, I want it to be the very last thing printed.

To stop fortunes from being displayed on login you can remove the executable bit on /etc/profile.d/bsd-games-login-fortune.sh (and/or /etc/profile.d/bsd-games-login-fortune.csh depending on the shell(s) you use) and it will not be run.
Code:

chmod -x /etc/profile.d/bsd-games-login-fortune.*
To display a custom message you can either add a script to /etc/profile.d/ that gets run each time you login, create a .bash_profile (or similar file for whatever shell you use) in your user's home directory that gets run whenever your specific user logs in, or edit /etc/motd to add a system-wide message (not a script) that gets displayed upon login in a login shell. Note that the motd file is modified on system boot to show the proper kernel version but only if the file's structure is correct. It should ideally look like this:
Code:

Linux 2.6.37.6
Other stuff written here...

where the version number is the kernel version number (this first line gets overwritten by rc.S).

stf92 08-06-2012 06:39 PM

So all executable files in /etc/profile.d get executed when an interactive login shell runs. But none of them writes stdout as I see, save for bsd-games-login-fortune.sh. Now if I want to retain this together with my message, which script will be run first (mine or bsd-games-login-fortune.sh)? Thanks for an illustrative post.

T3slider 08-06-2012 08:21 PM

Quote:

Originally Posted by stf92 (Post 4747588)
Now if I want to retain this together with my message, which script will be run first (mine or bsd-games-login-fortune.sh)? Thanks for an illustrative post.

From /etc/profile:
Code:

for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done

I believe bash expands file listings in alphabetical order, so if you want fortune to run but you want your script to run later, you should workaround this by naming it "zzz_scriptname.sh" or something similar. Obviously a little hacky but short of renaming all files in /etc/profile.d/ to contain numbered prefixes I can't see another way around it.


All times are GMT -5. The time now is 09:35 AM.