Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

command line parameters

Posted on 2005-03-09
17
Medium Priority
?
200 Views
Last Modified: 2010-03-05
i m doing following in my original script:

$string = "Rahul Shah";
$command = "ssh server_name  /u/rshah1/temp.pl QBS $string";
system($command);


my temp.pl script contains:
perint $ARGV[0]  :: $ARGV[1] \n";

the output i get after executing the script is:
QBS :: Rahul

what i want is:
QBS :: Rahul Shah
0
Comment
Question by:shahrahulb
  • 9
  • 7
17 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 13499035
$command = "ssh server_name  /u/rshah1/temp.pl QBS '$string'";
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13499064
Hi Ozo,

It didn't worked...
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13499098
the strange thing is, if i manually go to ssh server_name and then run the script  ./temp.pl QBS 'Rahul Shah', that works

but why it doesn't work thru my original script
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 85

Expert Comment

by:ozo
ID: 13499249
#or better
system "ssh","server_name","/u/rshah1/temp.pl","QBS","\Q$string\E";
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13499284
You are amazing, Mr Ozo... That worked...

from where you find all the solutions...can u give me some tips

Rahul
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13499348
oops. one more issue: i was using:
    my $s_now = time();
    print("$NAME: now = " . scalar(localtime($s_now)) . "\n");
    $string = "$NAME: now = " . scalar(localtime($s_now)) . "\n";
    $string .= "$NAME: using login host= $url\n$NAME: using username= $username\n\n$NAME: Request: GET $url\n";


after executing system "ssh","server_name","/u/rshah1/temp.pl","QBS","\Q$string\E";

the output i get is,
QBS  pos.pl: now = Wed Mar  9 14:00:17 2005

it does not print the line "using login host = .......


Strange
0
 
LVL 85

Expert Comment

by:ozo
ID: 13499405
Do you need those "\n" in there?  they are getting interpreted by ssh before /u/rshah1/temp.pl is called
0
 
LVL 85

Expert Comment

by:ozo
ID: 13499577
I mean, they are getting interpreted by the remote shell before /u/rshah1/temp.pl is called
"'\Q$string\E'"
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13500788
yeah. i need "\n"
its very important.

any solution ot my problem
0
 
LVL 85

Expert Comment

by:ozo
ID: 13502411
system "ssh","server_name","/u/rshah1/temp.pl","QBS","'\Q$string\E'";
0
 
LVL 85

Expert Comment

by:ozo
ID: 13502431
Note the '' in the "" 
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13502799
i get the output in following manner"
pos\.pl\:\ now\ \=\ Wed\ Mar\ \ 9\ 22\:20\:34\ 2005
pos\.pl\:\ using\ login\ host\=\ https..........

there is an extra "\" embebeded after evry word.

for your infomation, the contents of $string is:
 $string = "$NAME: now = " . scalar(localtime($s_now)) . "\n";
 $string .= "$NAME: using login host= $url\n$NAME: using username= $username\n\n$NAME: Request: GET $url\n";


Rahul
0
 
LVL 6

Expert Comment

by:Talmash
ID: 13503750
> You are amazing, Mr Ozo... That worked...

concise and bery true.
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13506379
it is not working for me. i m getting extra "\" character. how do i get rid of that
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13507139
OZO,

did u try executing:  system "ssh","server_name","/u/rshah1/temp.pl","QBS","'\Q$string\E'";
because i m getting extra "\" character

Rahul
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 13513302
I tried it with "Rahul\nShah", but not with "pos.pl: now = Wed Mar  9 14:00:17 2005"

$NAME="pos.pl";
$url='https..........';
$username="'Rahul'\n'Shah'";
 $string = "$NAME: now = " . scalar(localtime($s_now)) . "\n";
 $string .= "$NAME: using login host= $url\n$NAME: using username= $username\n\n$NAME: Request: GET $url\n";

$string =~ s/\n/\\\n/g;
$string =~ s/'/'"'"'/g;
system "ssh","localhost","perl","-e",'print\"@ARGV\[0,1\]\"',"QBS","'$string'";
0
 
LVL 1

Author Comment

by:shahrahulb
ID: 13517120
It Worked. :-)

can u please tell me how did u found the solution

Thanks a lot.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question