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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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...
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.
# /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 )
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.