Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-11-2005, 08:48 AM
|
#1
|
|
Member
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30
Rep:
|
Ubuntu How to run Python script on Login?
Hi,
I'm using Ubuntu Linux, I have python script, how to start it on every login and stay running on background until log off ?
Thank You
|
|
|
|
08-11-2005, 08:55 AM
|
#2
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
For an individual user, just add it to .bash_login in your users home directory.
|
|
|
|
08-12-2005, 12:21 AM
|
#3
|
|
Member
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30
Original Poster
Rep:
|
I open my home user folder, but there is no file at all except just a Desktop folder.
Anyway I'm mostly running script like this :
#python
>>import client
>>client.init()
how to do that? anyway can I just run the binary one without the script source ?
Thank You
|
|
|
|
08-13-2005, 01:24 AM
|
#4
|
|
Member
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30
Original Poster
Rep:
|
Is there a way easily add the binary code of my python program such in windows Programs - StartUp ?
Thank You
|
|
|
|
08-13-2005, 09:49 AM
|
#5
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
First create your python script..
Then in your .bash_login (create it if it doesn't exist) just call for the script by specifying the path and the python script name... for e.g:
/path/to/your/python/script/script_name.py
|
|
|
|
08-13-2005, 04:16 PM
|
#6
|
|
Member
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Rep:
|
what about before login
trickykid,
In the interests of pushing the envelope, what about before login? is possible to run any script at all, on boot? Say, a mp3 soundbite, before login?
|
|
|
|
08-13-2005, 04:20 PM
|
#7
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Re: what about before login
Quote:
Originally posted by stabu
trickykid,
In the interests of pushing the envelope, what about before login? is possible to run any script at all, on boot? Say, a mp3 soundbite, before login?
|
rc.local or any of your other startup scripts you can customize.. 
|
|
|
|
08-13-2005, 04:29 PM
|
#8
|
|
Member
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Rep:
|
cheers, thanks
|
|
|
|
08-14-2005, 10:32 AM
|
#9
|
|
Member
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30
Original Poster
Rep:
|
Hi trickykid,
I'm newbie in linux, doesn't quite understand many things linux, I'm just starting migrating from windows to linux.
I'm trying to create a .bash_login file and put :
/home/user/client.py
but that doesn't working, trying to put :
python
import client
client.init()
stil doesn't working, remove the "python" line also not working (each trying logoff and login).
If I didn't misunderstand, by using .bash_login do you mean that I should use Bash Script ?
After I'm reading the web, there is special start up bash file for init the system but the name is .bash_profile not .bash_login
I'm even tried to put /home/user/client.py in .bash_profile but nothing happen.
Anyway could you please help me out by step by step on how to do it, because I'm really confuse.
Thank You
|
|
|
|
08-16-2005, 12:19 AM
|
#10
|
|
Member
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30
Original Poster
Rep:
|
In .bash_profile , if I put python maybe it wil run it, but how can I input :
>>import client
>>client.init()
or is it really just put the path of my client.py it will working ?
because it doesn't 
or maybe the path is wrong ?
I tried :
/home/user/client.py
/user/client.py
both doesn't work
Please Help Thank You
|
|
|
|
11-13-2009, 04:36 PM
|
#11
|
|
Member
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67
Rep:
|
The file needs to be like this:
PHP Code:
#!/bin/bash
python /home/user/client.py
The first line identifies it as a bash script, and then it calls python and tells it to read the python script. It probably also needs to be marked executable:
PHP Code:
~> chmod +x .bash_login
Sorry no one was able to help you with this before.
Last edited by bleargh; 11-13-2009 at 04:38 PM.
|
|
|
1 members found this post helpful.
|
11-14-2009, 01:45 AM
|
#12
|
|
LQ Newbie
Registered: Jun 2008
Posts: 3
Rep:
|
You could also put the script invocation line in the python script like:
Code:
#! /usr/bin/python
import client
client.init()
Then set the script as executable:
Code:
chmod +x /home/user/client.py
Then you can reference it from your .bash_login, .bash_profile or .bashrc
Code:
/home/user/client.py
I don't normally use .bash_login but .bash_profile is only run for at login and .bashrc is run for every shell.
If you need your script run for all users, you can put your script in /etc/bash.bashrc, but I would read some of the comments in this file to see if it is right for your purpose.
If you are looking to have this script run at system startup. I would put the script in /usr/local/bin and then I would link to it in one of the /etc/rc#.d directories, probably /etc/rc3.d.
Code:
sudo ln -s /usr/local/bin/client.py /etc/rc3.d/K90client
Thanks
ksorge
|
|
|
|
11-14-2009, 01:51 AM
|
#13
|
|
LQ Newbie
Registered: Jun 2008
Posts: 3
Rep:
|
sorry, I didn't see the original post date. I hope you have figured it out by know.
klsorge
|
|
|
|
03-11-2012, 12:50 AM
|
#14
|
|
LQ Newbie
Registered: Mar 2012
Posts: 2
Rep: 
|
Python Script Running
To run a simple python script in ubuntu :
# python
>>> vi test_python.py
This is the python script :
#!/usr/bin/env python -----Note : This line is mandatory-------------
""" CGI test 1 - Check server setup."""
# Check the first python script
print "Content-type: text/html"
print
print "<h1> Hello Harsh </h1>"
print "<p> This is python_test.py"
-------------END--------------------
To run a python script :
1. # python test_python.py
or
2. # chmod +x test_python.py
# ./test_python.py
|
|
|
|
03-13-2012, 06:11 PM
|
#15
|
|
Guru
Registered: Jan 2001
Posts: 24,128
Rep: 
|
Quote:
Originally Posted by Harsh Gupta
To run a simple python script in ubuntu :
# python
>>> vi test_python.py
This is the python script :
#!/usr/bin/env python -----Note : This line is mandatory-------------
""" CGI test 1 - Check server setup."""
# Check the first python script
print "Content-type: text/html"
print
print "<h1> Hello Harsh </h1>"
print "<p> This is python_test.py"
-------------END--------------------
To run a python script :
1. # python test_python.py
or
2. # chmod +x test_python.py
# ./test_python.py
|
Umm, okay, but how does this relate to running one at login at the command line like the original question asked?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:55 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|