LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to automatic run a shell script at boot? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-automatic-run-a-shell-script-at-boot-675041/)

ceantuco 10-08-2008 08:41 AM

how to automatic run a shell script at boot?
 
hi guys!

I wrote my first useful shell script! :) now I would like to make it run as soon as I log in. where should I put the shell scrip to auto run?
thanks!

linuxer8786 10-08-2008 08:49 AM

Quote:

Originally Posted by ceantuco (Post 3304093)
hi guys!

I wrote my first useful shell script! :) now I would like to make it run as soon as I log in. where should I put the shell scrip to auto run?
thanks!

you should put your script in:/usr/local/bin

ceantuco 10-08-2008 09:00 AM

i just added the script to that location but it doesn't run. what else can I do?

dasy2k1 10-08-2008 09:06 AM

putting the script in /usr/local/bin just means you can type the name without having to type the full path

if you now out the command you use to exicute the script in your
~/.bashrc it will runn whenever you log in (if you log in graphically it may not run untill you open a terminal)

David the H. 10-08-2008 09:19 AM

If you're using KDE you can place it in ~/.kde/Autostart and it will run whenever you start your kde session. I know gnome has a similar folder somewhere as well.

I don't think placing it in ~/.bashrc is a good idea, because then it will run every time you open a new bash shell, not just on startup. Unless you want that behavior, of course.

Oh, and placing the script in /usr/local/bin will only allow you to run it by name only if that directory is set in your PATH variable. Most distros add this by default, but it's not guaranteed. /usr/local/bin is one of the recommended traditional locations in which to keep personal scripts and programs, however.

ceantuco 10-08-2008 09:32 AM

I put the file in ~/.kde/Autostart but the script doesn't run. what can I do?

David1357 10-08-2008 09:45 AM

Quote:

Originally Posted by ceantuco (Post 3304093)
I wrote my first useful shell script! :) now I would like to make it run as soon as I log in. where should I put the shell scrip to auto run?

From the man page for bash:
Code:

When bash is invoked as an interactive login shell, or as a
non-interactive shell with the --login option, it first reads
and  executes commands from the file /etc/profile, if that
file exists.  After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile, in that order,
and reads and executes commands from the first one that exists
and is readable.  The --noprofile option may be used  when the
shell is started to inhibit this behavior.

You can call it from one of those files. If none of those files exist, you can create them.

ceantuco 10-08-2008 09:54 AM

I created ~/.bash_profile and put my script there but it didn't start up when I logged in.
what else can I try?

WorldIsNotFair 10-08-2008 10:18 AM

are you using this script on the office ? what role are you in the office (user or admin ?)

.bash_profile should be created auto when admin create an user.

u should consult your admin then.

if it's your laptop / personal desktop , just su in n' put it in the /etc/rc.local ... hehehe

permalac 10-08-2008 10:35 AM

Quote:

Originally Posted by ceantuco (Post 3304093)
hi guys!

I wrote my first useful shell script! :) now I would like to make it run as soon as I log in. where should I put the shell scrip to auto run?
thanks!

may be you are interested on running the script once at boot, on that case you should put you your script in /etc/rc.local, this script is launched after all /etc/rc.d stuff. and with root privileges.

ceantuco 10-08-2008 11:23 AM

ok... This is a personal computer, I'm running as user. I placed my script on /etc/rc.local (I had to md rc.local) but my script didn't run when I logged in.

I also put it on /etc/rc.d but it didn't work!

last thing I did was to put the scrip on in /etc/init.d but nothing!

any ideas?

Thanks guys for your time! :)

David1357 10-08-2008 11:54 AM

Quote:

Originally Posted by ceantuco (Post 3304153)
I created ~/.bash_profile and put my script there but it didn't start up when I logged in.
what else can I try?

What is the output of
Code:

$ ls -al ~
Also, you might want to put a bit of logging in your "~/.bash_profile" script to make sure it
1) runs
2) executes your script without any errors

ceantuco 10-08-2008 12:31 PM

there u go:

drwxr-xr-x 37 cesar users 4096 2008-10-08 12:18 .
drwxr-xr-x 5 root root 4096 2008-09-09 10:52 ..
drwx------ 3 cesar users 4096 2008-09-09 11:42 .adobe
-rw------- 1 cesar users 4928 2008-10-08 12:17 .bash_history drwxr-xr-x 2 cesar users 4096 2008-10-08 10:50 .bash_profile
-rw-r--r-- 1 cesar users 1177 2008-09-09 10:44 .bashrc
drwx------ 7 cesar users 4096 2008-09-09 11:00 .beagle drwxr-xr-x 2 cesar users 4096 2008-09-09 10:44 bin
drwx------ 3 cesar users 4096 2008-09-29 16:09 .cache drwxr-xr-x 5 cesar users 4096 2008-09-29 16:08 .config
drwx------ 3 cesar users 4096 2008-09-22 16:01 .dbus
-rw-r--r-- 1 cesar users 51 2008-10-08 12:18 .DCOPserver_work__0
lrwxrwxrwx 1 cesar users 31 2008-10-08
12:18 .DCOPserver_work_:0 -> /home/cesar/.DCOPserver_work__0
drwx------ 2 cesar users 4096 2008-10-08 10:41 Desktop
-rw------- 1 cesar users 26 2008-09-09 10:44 .dmrc
drwxr-xr-x 4 cesar users 4096 2008-09-23 12:29 Documents
-rw-r--r-- 1 cesar users 315 2008-09-09 10:44 .dvipsrc
-rw-r--r-- 1 cesar users 1637 2008-09-09 10:44 .emacs drwxr-xr-x 3 cesar users 4096 2008-10-07 13:18 .emacs.d
-rw------- 1 cesar users 16 2008-09-09 11:18 .esd_auth
drwxr-xr-x 2 cesar users 4096 2008-09-09 10:44 .fontconfig drwxr-xr-x 2 cesar users 4096 2008-09-09 10:44 .fonts
drwx------ 2 cesar users 4096 2008-10-08 10:43 .gconf
drwx------ 2 cesar users 4096 2008-10-08 10:44 .gconfd
drwx------ 3 cesar users 4096 2008-10-08 10:43 .gnome2
drwx------ 2 cesar users 4096 2008-09-09 11:02 .gnome2_private
-rw-r--r-- 1 cesar users 16257 2008-09-09 10:44 .gnu-emacs
drwx------ 3 cesar users 4096 2008-10-06 10:31 .gnupg drwxr-xr-x 10 cesar users 4096 2008-09-09 15:40 .housecall6.6
-rw-r--r-- 1 cesar users 25058 2008-09-09 15:39 hs_err_pid3895.log
-rw------- 1 cesar users 185 2008-10-08 12:18 .ICEauthority
-rw-r--r-- 1 cesar users 861 2008-09-09 10:44 .inputrc
drwxr-xr-x 3 cesar users 4096 2008-09-09 15:38 .java
drwx------ 4 cesar users 4096 2008-09-15 09:50 .kde
drwx------ 3 cesar users 4096 2008-09-09 10:44 .local
drwx------ 3 cesar users 4096 2008-09-09 15:38 .macromedia
-rw-r--r-- 1 cesar users 3098 2008-09-29 12:30 .mailcap drwxr-xr-x 3 cesar users 4096 2008-09-09 10:48 .mcop drwxr-xr-x 4 cesar users 4096 2008-09-09 11:02 .mozilla
-rw-r--r-- 1 cesar users 299 2008-10-08 09:52 music.sh
drwx------ 3 cesar users 4096 2008-10-08 09:55 .ooo-2.0
-rw-r--r-- 1 cesar users 1028 2008-09-09 10:44 .profile drwxr-xr-x 2 cesar users 4096 2008-09-09 10:44 public_html drwxr-xr-x 2 cesar users 4096 2008-10-08 12:18 .qt
-rw------- 1 cesar users 34548 2008-09-29 16:01 .realplayerrc
-rw------- 1 cesar users 2078 2008-10-06 13:48 .recently-used
-rw-r--r-- 1 cesar users 218 2008-09-09 13:12 .recently-used.xbel
drwxr-xr-x 2 cesar users 4096 2008-09-09 10:44 .skel
drwx------ 2 cesar users 4096 2008-10-02 12:08 .ssh
drwx------ 4 cesar users 4096 2008-09-24 12:31 .thumbnails
drwx------ 2 cesar users 4096 2008-09-09 12:11 .tsclient drwxr-xr-x 2 cesar users 4096 2008-09-09 11:16 .wapi drwxr-xr-x 4 cesar users 4096 2008-09-25 16:12 .wine drwxr-xr-x 2 cesar users 4096 2008-09-09 11:19 .wireshark
-rw------- 1 cesar users 259 2008-10-08 12:18 .Xauthority
-rw-r--r-- 1 cesar users 1940 2008-09-09 10:44 .xim.template drwxr-xr-x 2 cesar users 4096 2008-09-29 16:02 .xine -rwxr-xr-x 1 cesar users 1446 2008-09-09 10:44 .xinitrc.template
-rw------- 1 cesar users 8816 2008-10-08 13:19 .xsession-errors
-rw-r--r-- 1 cesar users 40690 2008-09-29 16:08 .y2log
-rw-r--r-- 1 cesar users 281 2008-09-29 15:30 .y2usersettings

David1357 10-08-2008 01:37 PM

Quote:

Originally Posted by ceantuco (Post 3304289)
drwxr-xr-x 2 cesar users 4096 2008-10-08 10:50 .bash_profile

.bash_profile is supposed to be a file, not a directory. You put commands that you want to run at login in the file.

trickykid 10-08-2008 01:39 PM

The proper place would be .bash_login and not .bash_profile.

If you want things to run when you exit, put them in .bash_logout

Good outline of bash/shell initialization files:

http://tldp.org/LDP/Bash-Beginners-G...ect_03_01.html


All times are GMT -5. The time now is 04:41 AM.