Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Saturday, September 18, 2010

How to run custom scripts at Linux startup?

It is a good idea to make your own scripts at the Linux start up. Here I am explaining the things with a simple example. I want to make a directory in desktop named 'folder' in each start up. If it is deleted, a new 'folder' is created in the same place in the next start up. Here is what I did.
first make a new script- here 'my_own_script'. Open the file in gedit and add the following:
#! /bin/bash
# chkconfig: 345 40 60
mkdir /home/tom/Desktop/folder
You need to change to the correct path in 3rd line. Here 345 means different run levels and 40 and 60 are the order for start and stop. save the file in /etc/init.d .
Then open terminal and execute this command:
chkconfig --level 345 my_own_script on
Then restart you computer and you can see a directory named 'folder' on your desktop in each start up. For more details, use:
man chkconfig
The mkdir command can be replaced by your own custom scripts. This worked on my PC powered with fedora 12. I found in linux forums that, it will work on Redhat/CentOS/Mandriva.
Start up programs are sometimes irritating and delay start up. So if you want to turn off your script from next start up, use command:
chkconfig --level 345 my_own_script off

Monday, March 1, 2010

Welcome note on Puppy Linux boot up screen

Is it fun to display a welcome note with your name while booting up Puppy linux? If you think so, you can continue reading. Here I am telling how to set up your Puppy Linux to display "Welcome, {your name}" at boot up. Probably you can do this in other Linux based OS with slight or no modifications. But nowadays bulky operating system intentionally hide the boot up screen with a splash image.
First of all, navigate to /etc/rc.d
Then open 'rc.sysinit' . You should have root privileges in order to edit this file. Read carefully the 'Read me' file before going to do anything. If you are not going to take a risk, back up the file into any other externally accessible directory.
After you open the file in your favourite text editor, just go through the file, you will notice that, this script is automatically executed at every boot up. Go to the end of the file and append the following script.

##########CUSTOM SCRIPT##############
echo -n "

" >/dev/console
/bin/echo -e "\\033[10G\\033[1;34mWelcome, {Your name}\\033[0;39m" >/dev/console
echo -n "

" >/dev/console
sleep 2
###################################

Edit the script with your name instead of '{Your name}'. The script is nothing but an echo statement to the console. It is possible to change the display properties by changing the parameters along with the text. First test it in terminal and then write script is recommended. Now save the file and reboot.
Done.
If you avoid 'sleep 2' statement, you may not see the text at boot up. One best way is remove the line 'sleep 2' and set a login password for Puppy as I did. Then Puppy gives a cool welcome to you and then ask password.