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! |
Quote:
|
i just added the script to that location but it doesn't run. what else can I do?
|
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) |
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. |
I put the file in ~/.kde/Autostart but the script doesn't run. what can I do?
|
Quote:
Code:
When bash is invoked as an interactive login shell, or as a |
I created ~/.bash_profile and put my script there but it didn't start up when I logged in.
what else can I try? |
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 |
Quote:
|
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! :) |
Quote:
Code:
$ ls -al ~ 1) runs 2) executes your script without any errors |
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 |
Quote:
|
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 |
Quote:
If during login, use the .bash_login in you're users home directory. If at bootup before anyone logs in, put it in rc.local initialization file usually found in /etc/rc.d/ |
Quote:
Code:
$ ls -l /etc/profile Code:
$ ls -l /etc/login |
hey guys! I added my script to ~/.bash_login but still it doesn't run. I want the script to run when I log in (sorry about the confusion with the title)
I have /etc/profile and I DO NOT have /etc/login thanks guys! |
Quote:
|
the script is supposed to ask what type of music I want to listen to then I will answer and depending my answer it would open my sound files. I know it is not running because it doesn't ask me anything. Is it possible that I'm doing something wrong?
|
Quote:
Here's why I separate them though from one another, .profile, .bash_login and .bash_profile are more for the initial things you want done upon login but on each terminal or shell you open. When I want something specific to run when I login as in a specific command, etc, I'll put it in .bash_login. This just keeps things tidy really to me. Really you can have .bash_login, .profile and or .bash_profile to do everything you want initially when you login but .bashrc is really where it slightly differs from those and should be used for environment settings and aliases, etc. Say for instance if you're in X or GUI, each time you open a new terminal, it will search for .bashrc and not the others. I would imagine you might want a script to run upon initial login but not each time you want to run a new terminal or shell. |
Quote:
|
yes, I'm using the GUI! ok, so it is not going to work. what I wanted to do was something like a .bat file (for windows) where you could place it on the startup folder or the run key on the registry to make it run.
is that possible? |
Quote:
Also, did you do what I suggested and put some logging in "~/.bash_profile" (or "~/.bash_login)" to make sure everything is working the way you expect it to? If you are not adding any logging or debugging statements to your script, you are being lazy. Laziness will not solve your problems. |
wooowww you are being lazy. Laziness will not solve your problems are hard statements buddy. I'm not being lazy, at first I thought I had to create a dir and cp my shell to it but then I read that "~/.bash_login" and "~/.bash_profile" were files so I did that but it didn't work. Now I'm not a programmer so I DO NOT know how to add debugging statements.
|
Quote:
In your case, the root of the problem is that you have a "~/.profile" file, which takes precedence over the other two files. You need to call your script from the end of that file. |
Quote:
Code:
echo "This line got executed" >> ~/debug.log |
Thanks David I'll give it a shot!
|
Quote:
This may depend on what Desktop environment you use (might have to put it somewhere in an AutoStart ocnfiguration for Gnome, KDE or whatever you use) but something like this might work: xterm -e "/path/to/script" You can replace xterm with whatever terminal software you choose. And we should really stop the nonsense about members being lazy. Don't assume, just help or move on without all the negativity. |
Quote:
|
I don't know about KDE but under Gnome, you should have a Sessions in System > Preferences > Personal > Sessions
This is where you can add startup programs. I'm sure KDE has the same options, just couldn't tell you exactly the path to configure programs to startup within KDE at login. But you can add all you want to your bash initialization scripts, it's not going to work since you're not logging into a console and you're using a plain old bash script. It needs to be run in a terminal to work. ;) |
thanks Trickykid! I'll try it later! I appreciate your help!
|
Have you made sure you have proper execute permissions on the script as well? Perhaps you should tell us in more detail exactly what you've tried, i.e. what lines you've tried addding to the files and whatnot.
And pay attention to trickykid's comment about the script itself needing a gui. If the thing only runs in a terminal, then you're not going to see anything because it doesn't know how to open up a terminal window on startup so that it can ask you for input. You either have to use something like xdialog, kdialog, or gtkdialog in your script in order to get a window, or perhaps start it from a shortcut with the "run in terminal" option selected. ~/.kde/Autostart (or the equivalent in gnome) really should work, provided you have everything else working right. You could also keep the script somewhere else and create a shortcut to it in that directory. |
Quote:
Now if the script is doing something like "read", then you are right about needing to launch a terminal. However, I have been operating under the assumption that the script asked the question using a dialog. |
Hi David,
I ran chmod 755 [file] to give the proper permissions to my script and I'm able to run it when I type my file name and then hit enter. I just can't get the damm thing to run when I log in! This is very frustrating. |
Quote:
Of course a good way to test if it's actually getting executed is to add a few debugging lines and then check if anything new has been logged after login. |
ceantuco, how exactly does the script prompt you? Are you using any kind of gui dialog, or just the terminal prompt? Perhaps you could post it here for us?
|
All times are GMT -5. The time now is 06:47 PM. |