Run shell script automatically after Login.
Hi all,
I want run shelll script myScript.sh automaticaly after login. plz help me how can do in Redhat 7.2 |
Hi,
Im not sure about RedHat but in most distors there will be a file called rc.local (/etc/rc.local) and you can add anything you want to it, such as a path to a script or a list of commands. Hope that helps |
Try looking for a .bashrc file in your home directory
That should work, it will run every time a terminal is opened. - Owen. |
Quote:
If you want to run a script after you log in then you can try the .bashrc method as someone else mentioned, or if you're using a graphical desktop environment such as KDE or Gnome you can run it when they start up. I don't know how to do it in Gnome off the top of my head but for KDE look at my post in this thread. That way it will run just once, not every time you open a terminal. Which method you want to use will depend on what the script actually does. I assume you're aware that RedHat 7.2 is really, really old and way past the end of it's support life cycle. |
The directory /etc/init.d contains scripts which are to be loaded at boot time (/etc/rc.d/init.d in redhat)
But we have to put a link in the directories rc0.d,rc1.d,rc2.d and so on to run in the corresponding run levels These directories include filenames such as S07filename like that S indicates start the daemon and K indicates kill you can put the script in /etc/init.d/ directory and make a link in the corresponding run level directoreies. |
Hi,
You should setup a .bashrc & .bash_profile for your user account; Code:
sample .bashrc; Code:
sample .bash_profile; |
Actually it depends, and the OP isn't clear about that nor has he returned to elaborate. It should be clear that the /etc/init.d and /etc/rc.local parts of the SysV initscript structure have nothing to do with running scripts on user login. The .bashrc option, first mentioned by owenjh does, but misses one option for shells that adhere to that, using the globally accessable /etc/profile.d for running scripts. The benefit of running scripts from there is that a user will not be able to tamper with it and the administrator can choose (for example using `id -g` statements) to which users the script should apply.
|
Quote:
- What this script you want to run actually does. - Exactly under what circumstances you want it to run. (E.g. after you log in on a text session, a graphical session, every time you start a new shell (if so which shell?)) - If you're using a graphical desktop environment then which one. Quote:
|
Hi,
Quote:
|
Quote:
If you don't use any kind of graphical environment then you can call myScript.sh from ~/.bashrc or the equivalent file for whatever shell you're using if it's not bash. You log in, ~/.bashrc is parsed and myScript.sh gets run as a result. Calling myScript.sh from ~/.bashrc will also cause it to run if you log in via ssh. If you put the call in your ~/.bashrc and you're using a graphical desktop environment, I'll use KDE as an example, then every time the user opens Konsole (KDE's terminal app) then ~/.bashrc will be parsed and then myScript.sh will get run. In this scenario myScript.sh is not being run after login, it's being run every time a new shell is started in Konsole. Depending on what myScript.sh actually does then this may not be desirable behaviour. If you are using KDE and only want myScript.sh to run once after you log in, not whenever you open a new shell in Konsole, then you can have KDE call myScript.sh when it starts up, which is just after you log in. That way myScript.sh is only one once, right after you log in, and it is not run again at any point whilst you are logged in. So when saying you want to run a script after log in then it is advisable to provide information such as I suggested in my previous post because depending on what the script does and what, if any, desktop environment you are using makes a difference to running a script after log in is best achieved. Saying that you are using RedHat 7.2 is not useful information for the purposes of the question being asked because there is nothing special about RedHat 7.2 (unless you count that it's support life cycle ended at least six years ago) when it comes to running a script after you log in. Saying 'I use KDE and want to run a script just once after I log in' would be useful because then people would know to tell you that you can have KDE run scripts when it starts up and tell you how to do that. |
Hi,
The chicken or the egg scenario. Not much information from OP so we could all come up with different ways to handle a particular situation. His/her criteria was when the user login to the shell and wished to run myscript.sh. A little AI or even simple boolean would be a means to setup. The case wuld be nice if the OP would have been a bit more specific. |
Hi all,
Thanks for ur replies, Just i have added path in .bashrc file,it is working. |
run script once on login without gui
Quote:
I do not want it at boot time before login so the rc.d type locations are out. I only want it run once after initial machine boot up and initial login. The problem with .bashrc and .bash_profile means it gets run each time a terminal session is opened. I have been using Linux for a few years now but scripting is not my strong point so would appreciate some pointers on this. Many thanks |
erm you are aware that redhat 7.2 is several years out of date and should no longer be considered secure
you should upgrade to somthing a little newer |
cli question
Quote:
|
All times are GMT -5. The time now is 01:26 PM. |