Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I did a google search on your problem and ran across your previous thread. I was a bit confused. Are you having trouble running the python program as part of the login script, or are you having trouble running the python program in general?
If it is the latter, I know that I have to type 'python /home/user/my_program.py' in order to run the code. As this is not necessary in Windows, it took me a while to figure that out.
Do you mean when you login or when any user logs in?
In the first case you have to put "python /home/user/client.py" in your .bashrc file. In the second case, I think (but can be wrong) there is a /etc/profile file that is excecuted for every user.
enemorales: yep, there's a global profile; /etc/profile on my box.
IIRC, you're a bit wrong regarding .bashrc;
.bash_profile is sourced (i.e. run) for all your login-shells (fx. the C-M-F[1-6] ones)
.bashrc is sourced for all interactive shells (fx. in an xterm)
OP:
if it's for every user:
Code:
# echo "/path/to/script.py" >> /etc/profile
you may (or may not) also want to see the variable $USER.
IIRC, you're a bit wrong regarding .bashrc;
.bash_profile is sourced (i.e. run) for all your login-shells (fx. the C-M-F[1-6] ones)
.bashrc is sourced for all interactive shells (fx. in an xterm)
I'm probably too used to xterm these days. Thanks for the remark, jonas.
If the commands run fine in the python shell (the >>> prompt), then I should think that they would run in the exact same manner when executed from a python script file. I can't think of any reason why the system would treat the commands any different in this case.
I would just insert the command 'python /home/user/client.py' into the file that you choose to try like jonaskoelker suggested and see if it works.
But it doesn't run automatically when I'm insert the command into one of this :
.bash_login
.bash_profile
/etc/profile
I tried to insert at begining or end of the bash script, but still not run my program (I've test it by logoff and login)
Except for something weird, if I insert the command at the beginning of .bashrc file then the the script automatically run when I open the Terminal.
What I need is the script is run on every user login automatically.
will allow everyone on a system to execute the program. You may need to be root if the location where the script is is not somewhere where you have control of.
Hi Electro,
Already fix it to #!/usr/bin/python2.4
and tried again in several .bash_xxx logoff login still not working
I've delete the .pyc before test to know wether it is actually compiled or not, then the result is NO .pyc exists, so I think that seems bash didn't call to compile my script at all.
This is the script looks like is there anything wrong with it ?
#!/usr/bin/python2.4
from socket import *
def main():
s = socket(AF_INET, SOCK_DGRAM)
hostname = '192.168.100.100'
port = 1973
s.connect((hostname, port))
code = chr(203) + chr(214) + chr(201) + chr(198) + chr(001)
s.send(code + 'LINUX CLIENT PROGRAM MASUK MEJA ' + stationid);
if __name__ == "__main__":
main()
and when I tried to run it on terminal :
# python
Python 2.4.1 (#2, Mar 30 2005, 20:41:35)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import client
>>> client.main()
>>>
its work perfectly no error, so what is the problem really is, I'm really confuse, please Help
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.