LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-21-2005, 05:16 AM   #16
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47

when posting code, *always* put it in code tags.

try running your script as both:
Code:
$ ./client.py
$ /path/to/client.py
There are basically three scripts you need to know about: /etc/profile, ~/.bash_profile and ~/.bashrc;

you probably want to add yours to /etc/profile.

Just added a python script to my /etc/profile, it all acted as it should.

--Jonas
 
Old 08-22-2005, 05:19 AM   #17
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
I'm trying to do it but still not working after I tried logoff and login again

Unfortunately, maybe I'm misplaced something ?

Last edited by warnetgm; 08-22-2005 at 05:22 AM.
 
Old 08-22-2005, 05:20 AM   #18
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Halo Jonaskoelker,

Sorry for the code, now I know the rules, ok this is my /etc/profile

Code:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
if [ "$BASH" ]; then
PS1='\u@\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi

export PATH

umask 022
Please modify it so I can simply copy paste it into my /etc/profile, because I tried to put the


Code:
$ ./client.py
$ /path/to/client.py
in there but still not working unfortunately, maybe I'm misplaced it within /etc/profile...

Please Help, Thank You
 
Old 08-22-2005, 08:44 AM   #19
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Try running some other python code:
Code:
umask whatever
...

python -c "print 'hello, world'"
Does it work? Does `echo hello, world' work?

You didn't copy
Code:
$ ./client.py
$ /path/to/client.py
verbatim, did you? The $ is part of the prompt, not the command (which I'm sure you already knew).

hmm... *scratches head* --Jonas

Last edited by jonaskoelker; 08-22-2005 at 09:00 AM.
 
Old 08-22-2005, 06:03 PM   #20
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
There are many ways to run scripts. One way is

. /path/to/client.py

The . means run this script in the same environment as the script that ran it. Do not get confused with ./path/to/client.py because it is different.


The second way is

exec /path/to/client.py
or
/path/to/client.py

This way will run the script in another environment with unknown environment variables. Probably, it will use default environment variables that is set with bash, sh, csh, and other shells.


You may want to use "#!/usr/bin/python2.4 -d -t" in your script to check for tabs and warn if the tabs are inconsistent. Python is dependent on tabs or indents. The script that you posted does not have any indents to tell python which lines of code is part of other codes. I am a Python beginner, but you may want to add error catch commands to make sure it works correctly when it does have problems. The script should have a way to figure out if 192.168.100.100 can be access. Usually during boot, the profile script is run before the network is ever started. You probably want to run the python script as a daemon, so the python script can detect using a while loop if networking is up.
 
Old 08-22-2005, 11:19 PM   #21
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Jonas,
This is the code I'm trying :
Code:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games"
fi

#python /home/support/client.py


if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
	. /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 022

python -c "print 'hello, world'"

./client.py
./path/to/client.py
But it doesn't even compile the script since there is no .pyc file. Also the code print hello world, didn't show anything after I've logoff and login.

Electro,
Sorry actually the script have indent just it turn doesn't have indent when I'm paste here maybe because I didn't use *code* quote. This is the real one :
Code:
#!/usr/bin/python2.4 -d -t

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);
	stationid = '30';
	s.send(code + code + stationid + ' Games')

	code = chr(203) + chr(214) + chr(201) + chr(198) + chr(001)
	s.send(code + 'LINUX CLIENT PROGRAM MASUK MEJA ' + stationid);

if __name__ == "__main__":
    main()
I've also add -d -t but nothing happen after I've log off and login again.

You are right that I need the network running first ofcourse that is what I want to achieve by scripting this is to send data to the server program. So what should I do now ? what daemon work different ? anyway I still need to make sure that my program just running after each login and shutdown just when log off, while still running in the background other than that.

Actually before I'm migrate all of my clients into linux, I'm using WinXP, in there I'm create an exact program ( using Delphi) and add my program shortcut to StartUp folder. After that its working like I want it, the program executed after each login, and stay in the background to receive command by server program, and shutdown when the computer logoff/turnoff.

Actually I want to achieve that too in my linux clients, it must be possible, just I'm newbie to linux and so I didn't understand how linux work on something like that, but eventhough I know it will be hard, I have spirit and patience to learn )

Please Help
Thank You
 
Old 08-23-2005, 08:47 AM   #22
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Btw, what I said about bashrc being run at interactive clients turn out to be wrong. It say in /usr/share/base-files/dot.bashrc that ~/.bashrc is run on on starting non-login shells.

OP: try `python <absolute path to script>'

hth --Jonas
 
Old 08-23-2005, 11:35 PM   #23
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Do you mean absolute path is :

Code:
python /home/user/client.py
or anything else ? because that is already tested
 
Old 08-25-2005, 02:36 AM   #24
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
halo ? is there anything else I should do ?
 
Old 08-25-2005, 03:51 AM   #25
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
I'm out of ideas. I have *no* clue why this `just works' for me and not for you.

you may want to look at how I did it: http://jonaskoelker.homeunix.org/~jonas/transcript.txt

hth --Jonas
 
Old 08-30-2005, 10:12 AM   #26
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Hi Jonas,

Please see this is what I did to my /etc/profile

Code:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
  if [ "$BASH" ]; then
    PS1='\u@\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
	. /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

export PATH

umask 022

python /home/client/client.py
client@MIS:~$ cat /home/client/client.py
#!/usr/bin/python2.4 -d -t

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);
        stationid = '30';
        s.send(code + code + stationid + ' Games')

        code = chr(203) + chr(214) + chr(201) + chr(198) + chr(001)
        s.send(code + 'LINUX CLIENT PROGRAM MASUK MEJA ' + stationid);

if __name__ == "__main__":
        main()
but after I triend logoff and login again, unfortunately it still doesnt work
Please Help

Thank You
 
Old 08-30-2005, 10:30 AM   #27
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
And the strange is like ussual, it is always working when I Shutdown or Restart computer.
 
Old 08-30-2005, 02:00 PM   #28
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Hmm...

Try inserting a `print "hello, world"' in the script.

Try giving the absolute path to python (i.e. /usr/bin/python /home/client/client.py)

Echo something right before the line w. `python', to make sure control gets there.

Make sure the file is world-readable.
 
Old 08-31-2005, 12:02 AM   #29
warnetgm
Member
 
Registered: Aug 2005
Distribution: Ubuntu
Posts: 30

Original Poster
Rep: Reputation: 15
Ok I will try that,

But could you explain, why the script only being executed correctly when I'm Turn Off or Restart ?
Other than that, such as when I'm starting linux or logoff or login, the script never got executed.
Just when Turn Off the script Run.
I think there gotta be something here, the script is OK and run but only not at the moment I've expected.

Do you have any idea regarding that ?
 
Old 08-31-2005, 08:00 AM   #30
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Quote:
Do you have any idea regarding that ?
No, I'm totally out of ideas.

--Jonas
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu How to run Python script on Login? warnetgm Linux - General 14 03-13-2012 06:11 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
python script LinuxLala Programming 14 04-07-2004 06:19 AM
/.bash_profile setup to run java program mohapi Fedora 10 01-22-2004 07:43 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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