LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 08-11-2005, 08:48 AM   #1
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Rep: Reputation: 15
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
 
Old 08-11-2005, 08:55 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
For an individual user, just add it to .bash_login in your users home directory.
 
Old 08-12-2005, 12:21 AM   #3
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
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
 
Old 08-13-2005, 01:24 AM   #4
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Is there a way easily add the binary code of my python program such in windows Programs - StartUp ?

Thank You
 
Old 08-13-2005, 09:49 AM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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
 
Old 08-13-2005, 04:16 PM   #6
stabu
Member
 
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Blog Entries: 5

Rep: Reputation: 32
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?
 
Old 08-13-2005, 04:20 PM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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..
 
Old 08-13-2005, 04:29 PM   #8
stabu
Member
 
Registered: Mar 2004
Location: dublin IRL
Distribution: Slackv12.1, Slamd64v12.1,Xubuntu v8.10_64, FC8_64
Posts: 438
Blog Entries: 5

Rep: Reputation: 32
cheers, thanks
 
Old 08-14-2005, 10:32 AM   #9
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
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
 
Old 08-16-2005, 12:19 AM   #10
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
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
 
Old 11-13-2009, 04:36 PM   #11
bleargh
Member
 
Registered: Jul 2004
Location: New York, NY
Distribution: Ubuntu
Posts: 67

Rep: Reputation: 16
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 +.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.
Old 11-14-2009, 01:45 AM   #12
ksorge
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 1
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
 
Old 11-14-2009, 01:51 AM   #13
ksorge
LQ Newbie
 
Registered: Jun 2008
Posts: 3

Rep: Reputation: 1
sorry, I didn't see the original post date. I hope you have figured it out by know.

klsorge
 
Old 03-11-2012, 12:50 AM   #14
Harsh Gupta
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
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
 
Old 03-13-2012, 06:11 PM   #15
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by Harsh Gupta View Post
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?
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Python Script in UBUNTU Session Manager warnetgm Linux - Newbie 2 12-06-2006 03:08 PM
how to Run python script on .bash_profile warnetgm Linux - Newbie 32 09-08-2005 05:56 AM
run a script once at login? masand Linux - Software 4 05-02-2004 09:41 AM
Run script at login instead of bash uzi4u Linux - General 2 04-28-2004 02:31 PM
run a script once at login? shanenin Linux - Software 2 04-25-2004 10:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:48 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