?
Solved

command line parameters

Posted on 2005-03-09
17
Medium Priority
?
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 84

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
Industry Leaders: 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!

 
LVL 84

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 84

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 84

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 84

Expert Comment

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

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 84

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

Industry Leaders: 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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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

777 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