LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-08-2008, 08:41 AM   #1
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Rep: Reputation: 88
Wink 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!
 
Old 10-08-2008, 08:49 AM   #2
linuxer8786
Member
 
Registered: Sep 2008
Posts: 43

Rep: Reputation: 15
Quote:
Originally Posted by ceantuco View Post
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

Last edited by Tinkster; 10-30-2010 at 03:44 PM.
 
Old 10-08-2008, 09:00 AM   #3
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
i just added the script to that location but it doesn't run. what else can I do?
 
Old 10-08-2008, 09:06 AM   #4
dasy2k1
Member
 
Registered: Oct 2005
Location: 127.0.0.1
Distribution: Manjaro
Posts: 963

Rep: Reputation: 36
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)
 
Old 10-08-2008, 09:19 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.

Last edited by David the H.; 10-08-2008 at 09:23 AM.
 
Old 10-08-2008, 09:32 AM   #6
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
I put the file in ~/.kde/Autostart but the script doesn't run. what can I do?
 
Old 10-08-2008, 09:45 AM   #7
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
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.
 
Old 10-08-2008, 09:54 AM   #8
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
I created ~/.bash_profile and put my script there but it didn't start up when I logged in.
what else can I try?
 
Old 10-08-2008, 10:18 AM   #9
WorldIsNotFair
Member
 
Registered: Jun 2008
Location: Jakarta
Distribution: CentOS 5
Posts: 89

Rep: Reputation: 17
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
 
Old 10-08-2008, 10:35 AM   #10
permalac
Member
 
Registered: Jul 2007
Location: Barcelona
Posts: 115

Rep: Reputation: 16
Quote:
Originally Posted by ceantuco View Post
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.
 
Old 10-08-2008, 11:23 AM   #11
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
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!
 
Old 10-08-2008, 11:54 AM   #12
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
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
 
Old 10-08-2008, 12:31 PM   #13
ceantuco
Member
 
Registered: Mar 2008
Location: New York
Distribution: Debian
Posts: 809

Original Poster
Rep: Reputation: 88
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
 
Old 10-08-2008, 01:37 PM   #14
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by ceantuco View Post
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.
 
Old 10-08-2008, 01:39 PM   #15
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automatic executing shell script at booting raj_deep2k1 Linux - Networking 3 01-25-2006 07:36 AM
How to run a shell script on boot up? AussieGit Linux - Newbie 4 11-02-2005 06:10 PM
Run shell script in RedHat after boot dmorse Linux - General 1 08-23-2005 01:54 PM
RH8 - how to automatically run a shell script at boot time nu-B Linux - Newbie 2 11-03-2003 02:47 PM
RH8 - how to automatically run iptables rules shell script at boot time nu-B Linux - General 1 10-29-2003 08:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration