Is there a universal linux/unix startup script to append to? - linux

After researching, it seems that it would be easier to add commands to an existing script as opposed to creating a startup script for each of my needs. I am trying to get a series of repititive tasks done at system startup like:
sudo mkdir -p ~/scripts
sudo mount -t vboxsf scripts ~/scripts
Instead of finding a methodology for each system (I read that start script vary from system to system), I would like to know if there is a universal scripts to append this too (like I have done with environment variables in /etc/environment). Is there a universal file I can target to do these mounts?
Thanks, Yucca

some distributions (Redhat/CentOS) have /etc/rc.local exactly for this task. On openSuSE it is /etc/init.d/after.local

Take a look at initd
http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/

Related

What lilo option should I use to set a script to run when my linux system reboots?

I want to set a script to run when my Linux system reboots. What lilo option should I use?
lilo -R
lilo -S
lilo -T
lilo -L
Please suggest.
It depends on the flavour of the OS, but chances are that if you look into /etc/rc.local you find:
This script is executed at the end [of the boot] ... by default this script does nothing
so you can write commands directly into this file (ensure it is executable) or call from there any script you can put where you want.
EDIT: I said this already in a comment above but, for completeness, it is better to say it again here. The ability to start a user defined script or command is a basic feature of a good operating system - even DOS (and earlier OSes) had it. Instead, boot loaders are meant to load an os, not to fiddle with it. While LILO and other bootloaders can in some way interact with the system (kernel) being loaded, this capability is to be used to solve hardware or similar problems, not to override the OS way to do things.

Script in a embedded linux

I believe that this is a silly question but is my first time in wich I do a script. I am working on Linux, in an embedded system, and I think that what I want to do is quite simple but for me is not working.
I need to set an ip, start the startx & server for graphical mode and give to my application permission and run it, so I try like this:
#!/bin/sh
#
#Start
#
echo "Start......"
ifconfig eth0 X.X.X.X
startx &
cd /home
chmod a+x myApplication
./myApplication
exit $?
And then I save my script like S80script and I put it in the /etc/init.d folder.
I ran it but after throw the startx server my application is not run.
How can I do this in a propertly way?
There is another way for do this?
Thank you so much and sorry because maybe it is a beginner question.
If your application need to acess the XServer than you need to export the DISPLAY environment variable.
Try to run the application using:
DISPLAY=:0 ./myApplication
I would suggest you to install (for learning purposes) Linux on your laptop, and become familiar with Linux and scripting on your laptop. Then, replace during debugging phase the first line #!/bin/sh with #!/bin/sh -vx or #!/bin/bash -vx if you can run that script in a terminal. You could also use logger(1) in your script. Read the Advanced Bash Scripting Guide even if it is imperfect.
startx is configurable (read the linked man page), and is starting some client applications (configured in e.g. /etc/X11/xinit/xinitrc or in $HOME/.xinitrc...); so you should start your $HOME/myApplication from that file.
BTW, you could invoke startx in some init script like /etc/rc.local or whatever is appropriate for your Linux distribution.
BTW, you almost certainly need a window manager (to be started after your backgrounded application, as the last command, probably in the same xinitrc....).
At last, your embedded Linux distribution probably has some other files and scripts to start the network. You should configure your network parameters appropriately (on Debian and related, you could do that in /etc/network/interfaces)

Linux startup script instead init.d

newbie question... how can I get my script init script to start when linux boots. Can I just drop a script into the /etc/init.d directory and make manual links to rcX.d?
Thanks
The file /etc/rc.local is a good candidate for local jobs, and it avoids some of the complexity of using /etc/init.d/ and similar directories.
Just add a line to /etc/rc.local to launch your job.
Yes, you are right. You can read on this: http://www.cyberciti.biz/tips/linux-how-to-run-a-command-when-boots-up.html

Scripting Linux to install several programs at once

I've been installing step by step video conversion codec and tools for a few hours now, and it is just plan annoying. Is it possible to design a script to load in linux to do all the commands in sequence one after another?
Absolutely. Create a plain text file, put #! /bin/bash at the top, then write all the commands in the file. Save it, "chmod +x yourFile", then run it by calling ./yourFile.
If your installs are a more intricate, I'd need to see an example to say more specifically how to do this as a shell script.

Add to $PATH in linux so that it's available to daemons

Where can I add to a $PATH so that it's available to all daemons? So that it's "included" or "sourced" before daemons start?
Many thanks!
One option would be /etc/profile.
I may have misread that, if you want to run something before daemons you could create a cron job or...
The system startup files are located in /etc/rc2.d. You can add a file to this directory with the commands you want to run at system startup. Suppose you want to delete some temp files at system startup, you could put a file named TempFileDel in your /etc/rc2.d with the commands to delete your temporary files, so it'll run every time system reboots.
Helo.
As shereenmotor says, usually, startup scripts are located in /etc/rc2.d, but this depends on the UNIX/Linux you run and your system's default run level.
But I'm afraid it's not that easy. The script name must follow some rules:
- There are two kind of scripts, let's say: kill scripts and start scripts. Both stored in /etc/rcX.d.
- kill scripts are executed first, after that start scripts.
- kill scripts name must start with a "K".
- start sctipts name must start with a "S".
- Following the first letter, there must be a two digit number. This lets "rc" know the order for the execution of the sctrips. rc is the "master" script which calls the others. Have a look at your /etc/inittab.
- Finally, a name of your choice.
when "rc" calls this scripts it adds a parameter: start for "S" scripts and stop for "K" scripts. This allows you to use the same script for both operations, just using links.
create a file
#!/bin/ksh
case $1 in
start)
echo Removing file...
rm /tmp/somefile;;
stop)
echo bye!;;
esac
and then
ln -s /path/to/TempFileDel /etc/rc2.d/S10TempFileDel
ln -s /path/to/TempFileDel /etc/rc2.d/K10TempFileDel
Daemons are started many different ways on different varieties of UNIX. Most of them have a way to setup the environment.
Perhaps the most fundamental is to set the environment for the init process, often through /etc/inittab. This will set the starting environment for all processes in the system.
If you have a script or a command, you could put it in /bin/ and set the appropiate owner and permisions using chmod and chown

Resources