I am putting this question once again because I was unable to solve from problem by the replies I got earlier. Here I am providing you with modified code of my script I want to run this script from remote machine through ssh. (ssh user@machine_name perl sar1.pl -e start -p -wW -i 3) this way... But I am unable to run this script, while if It is running fine on local machine ( also by logging into remote machine through ssh shell and running from the shell) But I want this to run directly as I specified earlier.. I know from earlier replies that some part of the script is running and it is unable to detach from ssh . Kindly reply with solutions.. Here is entire code of my script-
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; #variable declaration my $exec_mode; my $param; my $paramfile; my $log_loc= "/logs/default_log.txt"; my $interv =2; GetOptions( "e=s" => \$exec_mode, "p=s" => \$param, "pf=s" => \$paramf +ile, "l=s" => \log_loc, "i=i" => \$interv); if($exec_mode eq 'start') { if( $paramfile eq NULL) { &startsar ($param, $interv); } else { &startsar ($paramfile, $interv); } elsif($exec_mode eq 'stop') { &stopsar ( $log_loc); } else { print " usage sarexec -arguemrnts are-\n -e <start>/<stop>\n -p <p +arams> \n -pf <param_file> \n -l <location> (by default location is ' +/logs/default_log.txt')\n -i <interval> ( by default interval is 2)\n + " } sub startsar { if (substr($_[0],0,1) eq "-") { my $pid = fork(); if($pid>0) { #parent } else { system("sar -o logfile $_[0] $interval 0 + > /dev/null&"); # this utility must run in background and able to cl +ose the script exit 0; } } else { chomp $_[0]; my $param; open FH,"< $_[0]" or die"cant open the fil +e"; $param = <FH>; close FH or die "cant close the file"; chomp($param); my $pid = fork(); if($pid>0) { #parent } else { system("sar -o logfile $param $interval + 0 > /dev/null&"); # this utility must run in background and able to +close the script exit 0; } } } sub stopsar { system("kill \$(pidof sadc)"); system("sar -f logfile>>$_[0]"); }

Edited by planetscape - added link to previous question, to which this is a followup

( keep:1 edit:16 reap:0 )


In reply to Running Perl Script on ssh from remote machine by agaream

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.