Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

how to run your program when the system is started....

by anonymoushydrogen (Initiate)
on May 24, 2008 at 13:28 UTC ( [id://688293]=perlquestion: print w/replies, xml ) Need Help??

anonymoushydrogen has asked for the wisdom of the Perl Monks concerning the following question:

<>Dear MONKS!

suppose i have a program

eg.

#!/usr/bin/perl

print "Hello to all monks"; i want to run it as soon as the user log in the window or linux operating systems? help me out dear
  • Comment on how to run your program when the system is started....

Replies are listed 'Best First'.
Re: how to make a run a orogram as sooon as linux is being started
by mwah (Hermit) on May 24, 2008 at 13:56 UTC

    (Not exactly a Perl question, but often puzzles unix/linux newbies.)

    Two things here. The first one:

    how to make a program run as soon as linux is being started

    ... is usually beeing accomplished by putting the program invocation into the appropriate startup file, most probably (you mentioned "Linux" which one?) the file etc/init.d/boot.local, like mine:

    $> cat /etc/init.d/boot.local

    starts the cpu temperature sensors package:

    #! /bin/sh modprobe w83627hf sleep 1 # optional /usr/bin/sensors -s

    the other question was:

    how to make my program run atomatically as as soon as somebody log into the linux system

    Same thing here, put the command into the appropriate file, for bash login shell, this might be the file ~/.bashrc in your home directory.

    For example, you have a program called 'anonymoushydrogen.pl' in your home directory, which contains the following code:

    #!/usr/bin/perl print "Hello anonymoushydrogen!\n";

    then, you may put the command:

    perl ~/anonymoushydrogen.pl

    into your .bashrc and all is fine.

    But: the exact name of the file may depend on your shell or login configuration (.bashrc, .profile, .bash_profile etc.).

    Regards

    mwa

Re: how to run your program when the system is started....
by tachyon-II (Chaplain) on May 24, 2008 at 14:06 UTC

    If you just wanted to display something then "message of the day" aka /etc/motd will do what you want. The contents of /etc/motd are displayed by login(1) after a successful login but just before it executes the login shell.

    If you want to execute a program when the system starts there are multiple methods and it depends on the system. On linux just add a line to /etc/rc.local and it will get executed at the end of the startup sequence. One win32 see this for the registry run keys and the startup folder hacks.

    To execute something when a user logs on in linux just stick a line in /etc/profile for a global effect or any of ~/.bash_profile ~/bash_login ~/.profile for a per user effect. On win32 it really depends on your setup. See this drag and drool example. For more examples try Google. "linux logon script" "windows logon script" should work well.

Re: how to run your program when the system is started....
by moritz (Cardinal) on May 24, 2008 at 14:19 UTC
    i want to run it as soon as the user log in the window or linux operating systems
    Most linux distributions use PAM for authentication, perhaps you can hook your script into one of the /etc/pam.d/common-* files.
Re: how to run your program when the system is started....
by MidLifeXis (Monsignor) on May 24, 2008 at 14:18 UTC
Re: how to run your program when the system is started....
by superfrink (Curate) on May 25, 2008 at 15:38 UTC
    i want to run it as soon as the user log in the window or linux operating systems?
    If you are using BASH on Linux and other unix-like systems edit ~/.bash_profile. If you are using CSH edit ~/.login . See the man pages for bash and csh.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://688293]
Approved by randyk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found