Doing SSH via PERL [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to login to a different shell in a different server. So i wrote the following code.
#!/volume/perl/bin/perl
use lib qw(/volume/labtools/lib);
use Net::SSH::Perl;
my $host = 'wd-shell2';
my $cmd = "cd /volume/ftp/private/det/os;ls -lrt jinstall*";
my $user = 'joydeep';
my $pass = '';
my $ssh = Net::SSH::Perl->new("$host", debug=>0);
$ssh->login($user, $pass);
my($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "\n$stdout\n";
I am not sure, whether i wrote it right or not. i am in tts-shell1, how can i login to wd-shell2 and do my thing with the code(after correcting). Please help me here.

First off, always include use strict; and use warnings; at the top of EVERY perl script.
Secondly, you should turn on debug mode so the module will give you as many helpful messages as possible:
my $ssh = Net::SSH::Perl->new("$host", debug => 1);

Related

How to deal with a c++ program taking runtime input in bash file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
In detail, I have a c++ program which takes runtime input of different parameters. I am creating a shell script to automate my process. But the program needs input to be given in the terminal. How do I send the input value from bash when the terminal prompts to enter the input value?
You can use usual flow (pipelining or redirecting) to feed your program with data
./a.out < myFileWithdata.txt
#or with pipelining
echo "my one line" | ./a.out
Another option is to use "here-document":
./a.out << EOF
My first line!
My second line.
EOF
#more commands
Note: EOF is just a convention, it can be any string that will mark end of data to pass to program.
Another option, to pass one line quickly is "here-string":
./a.out <<< "My data!"
#more commands

Extracting date from the format [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am struggling through this date extraction. I have a date like this
("D("yyyy-mm-dd")).
I want to get this "yyyy-mm-dd" and I cannot strip ("D(") this also because I have this format in other places so I tried like this
first searching the string but I am not sure if I am on right track
eg. intabc = istrdate.SearchSubString("D(");
so please suggest how can I get this value.
Input is
"(D(YYYY-MM-DD))"
OUTPUT that I want
(YYYY-MM-DD)
What i have done(not correct way I think )
intabc = istrdate.SearchSubString("D(");
you can use substr() and string::erase() functions in c++98
string str = "\"D(\"yyyy-mm-dd\")";
string result = str.substr(3);
result.erase(result.end() - 1)
result.erase(result.end() - 1)
if you are using c++11 you can also use string::pop_back() method.

Replace the words "can't, don't" by "can not, do not" using python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I need to replace words like "{can't, don't, won't }" by "{can not, do not, would not}" using python
The problem is:
"can't" can be detected by checking suffix "n't", so we can replace "n't" by "not"
But how can we transform "ca" to "can" as when we split "can't" it should be transformed to "can not"?
Since the rules of English are large and sometimes inconsistent, your best bet is probably just to set up full word maps rather than trying to figure out on the fly which letters are represented by the apostrophe.
In other words, a dictionary with values like:
can't -> can not
don't -> do not
won't -> will not
:
oughtn't -> ought not

How to check the format of keyboard input for a Perl script? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My Perl script just takes whatever you give as an input, and I want make it more robust by checking the pattern of the input string. My input string has to be in the format xxxxx-xxxx-xxxx. How can I check that?
$foo =~ /^.{5}-.{4}-.{4}\z/s
For example, this will repeatedly ask for the value until it gets a valid one.
my $foo;
while (1) {
print("Please provide foo (xxxxx-xxxx-xxxx): ");
my $foo = <STDIN>;
die("EOF\n") if !defined($foo);
chomp($foo);
last if $foo =~ /^.{5}-.{4}-.{4}\z/s;
print("Invalid input\n");
}

how to replace ’ with ’ in perl [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have below piece of code in Perl
my $file2 = "devil’s-claw-extract.html";
$file2 =~ s/’/’/ig;
print "$file2";
This code is working fine(means replacing ’ with ’) when running in konsole but not working in browser.
Please help me out.
Of course it “works”, and I will believe so until you produce a self-contained example that indicates otherwise.
Your first problem is that you are reinventing the wheel, there already is a module on CPAN to do such escaping for you:
use utf8; # because this source file contains special chars
use HTML::Entities;
my $file2 = "devil’s-claw-extract.html";
print encode_entities $file2;
Output:
devil’s-claw-extract.html
or with encode_entities_numeric:
use utf8;
use HTML::Entities 'encode_entities_numeric';
my $file2 = "devil’s-claw-extract.html";
print encode_entities_numeric $file2;
Output:
devil’s-claw-extract.html
Secondly, it is worth noting that your input string contains ’, a single right quote. This has the codepoint U+2019 (not U+0092, which is in a private use area. Conveniently, it decodes to ’ in the Windows-1252-encoding, but the actual encoding should always be explicitly set).
The apostrophe ', which you likely wanted, is U+0027 or &apos;.