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

I'm looking to run a perl script in the background of a linux server. I have done this before with other programs but this new scripts is not working. The script I want to run in the background is a client that uses IO::Socket to connect to a server and transfer telemetry (gutted):
#! perl -slw use strict; use IO::Socket; use XML::Simple; #use Data::Dumper; $SIG{PIPE} = "IGNORE"; $\="\n"; my $img = '"http://updraft.unl.edu/~uas/uas/uas.png"'; my $post_time; my $test; my $xs = XML::Simple->new( RootName=>'Telemetry', XMLDecl => 1); for (;;){ my $tele_client = IO::Socket::INET->new( 'localhost:12345' ) or pr +int $!; my $way_client = IO::Socket::INET->new( 'localhost:56789' ) or pr +int $!; while( <$tele_client> ) { ################################# } print "SLEEP"; sleep 10; }
The script I use to run this program in the background follows (cshell script):
at now << EOF uas-client.pl EOF exit
For some reason this script wont run in the background of the linux server. typing  ps -u uas in the terminal after running the cshell the client script doesnt show up. The idea here is to have an autonomous client that will continuously try to connect to the localhost so that when the data is availible it does not require the user to manually start the script. Any ideas?

Replies are listed 'Best First'.
Re: Running Client in Background
by chrism01 (Friar) on May 06, 2008 at 05:09 UTC
    If I wanted a background prog I'd use

    nohup uas-client.pl > uas-client.log 2>&1 &

    instead of at....

    Your print statements need somewhere to output.
    also, why
    use threads;
    ?

    Cheers
    Chris

Re: Running Client in Background
by pc88mxer (Vicar) on May 06, 2008 at 05:26 UTC
    Do you get any mail from the at job? Any output (stdout or stderr) produced by the program will be mailed to you when the process exits. So, if you are not getting any mail, perhaps your job is stilling running and the ps command is just not locating your process. Try using:
    pstree -p
    and look for children of atd. You can also use the atq command to see if your job is still in the batch queue.
Re: Running Client in Background
by mscharrer (Hermit) on May 06, 2008 at 07:35 UTC
    Did you tried to detach the perl script from the terminal using:
    fork && exit;

    at the very start?
Re: Running Client in Background
by brechin (Initiate) on May 06, 2008 at 14:50 UTC
      when using Proc::Daemon, what is listed when you type  ps -u uas in the linux terminal? Is there a way to give this process a name?