Hi Feherke,
Sorry for that I did not make myself clear. Let me restate my question:
The hostname() may return one of the following four values:
1) foo
2) foo.xyz.com
3) foo.bar.xyz.com
4) foo.bar
In either case, I want to return $from as foo@xyz.com or foo@bar.xyz.com in one-liner perl.
Your...
Let's say I have a baseline file like this:
4.1.27-4.1.2-amd64-1cccde6e81b2c42b
cmos2q installed and running
lm-sensors2q installed and running
lspci2q installed and running
mcelog2q installed and running
mpt2q not needed
pmbus2q installed and running
smartmon2q installed and running
And a...
Hi Feherke,
I want to follow up on this thread.
Let's say hostname() returns a host w/o domain name like this: foo.bar. I have to admit this is a rare hostname and I have never seen it before. But it's possible, right?
My question is how to still return the $from as 'foo@bar.xyz.com'? I...
Hi, Feherke,
I have a follow-up question.
Some people like one-liner because it's sophisticated. Some people hate it because it's hard to read and sometimes less efficient (e.g. one-liner to check a prime number). In the case above, getSender() vs. getSender2(), what's your opinion? Which way...
I have a piece of codes constructing an email sender:
sub getSender {
my $host = hostname;a # use Sys::Hostname;
my $domain = 'xyz.com';
my $char = '.';
my $from;
if($host =~ /$domain/) {
# hostname() may return a string like foo.bar.xyz.com and in this case
# we want to...
I know this line works:
print "OK!! Child($$, $pid) $res ended with ", $? >> 8; print "\n";
But how do I assign the line above into a variable? e.g.
$logMsg .= "OK!! Child($$, $pid) $res ended with ", $? >> 8;
$logMsg .= "\n";
While compiling it, I got this:
Useless use of right bitshift...
I got the solution. I need to set up two ENVs to make cron job run. Basically calling setEnv() before invoke gwsh. My sample code is listed below:
sub setEnv {
my $sshPid = getSshPid(user=>$ENV{LOGNAME}, psName=>'ssh-agent');
my $sshAuthSock = getSshAuthSock(sshPid=>$sshPid);
my %newEnvs =...
In addition, while the code is executed at cmd prompt, following three variables are the same as my own login ID:
$ENV{ LOGNAME }, getpwuid( $< ), & $ENV{ USER }.
However, while it's executed by the cron job, then $ENV{ USER } is undefined. But both $ENV{ LOGNAME } and getpwuid( $< ) are still...
A simple code just like this:
my $cmd = "gwsh root\@$ip \"uname -r\"";
my $ret = `$cmd`;
When I ran the code at cmd prompt, it's fine.
But when it's run in a cron job, $cmd returns nothing.
What did I miss here?
Many thanks.
Hi Chris,
Thanks for your input. Tcpdump can send lots of messages through stderr, even if it's not an error at all. That's why I am using 2>/dev/null. In addition, tcpdump cannot exit out by itself. In a script, you can either run it in a child process or in background.
Thanks agian.
Thank you, Feherke, for your help.
I found the solution. All I did was to let it sleep for one second after tcpdump. The '-n' switch does not make the difference, though. But, again, thank you. It's still good to know the '-n' switch.
Hi Experts,
I have a very simple script listed below:
#! /usr/bin/perl
my $cmd = "ssh root\@198.18.154.133 \"/a/sbin/tcpdump -v -n -i eth0 port 11640 -w /tmp/mytcpdump.pcap 2>/dev/null\" 2>/dev/null &";
system($cmd);
my $cmd2 = "/usr/bin/ssh root\@198.18.154.130 \"cd /tmp; ./go_load...
Thank you, rharsh. Your solution works very well.
Now, how to solve the problem below:
Sample Code:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long qw(:config no_auto_abbrev);
my ($email, $debug);
GetOptions(
"d" => \$debug,
"e=s" => \$email,
) || die;
if($email) {
print...
I am having difficulties in installing XML::LibXML.
Below is my system:
% cat /etc/issue
Ubuntu 14.04.2 LTS \n \l
% perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
(with 41 registered patches, see perl -V for more detail)
I have...
To rharsh,
Thank you for pointing out the perldoc. I just read it:
But when I set the environment in the code, I don't see the difference:
$ENV{POSIXLY_CORRECT} = 1;
Am I setting the $ENV{POSIXLY_CORRECT} correctly syntax-wise? OMG, I feel so retarded.
#!/usr/bin/perl
use strict;
use...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.