I'm trying to simulate a socket client using simple perl program.
socket client:
#!/usr/bin/perl
#path: /home/nuthan/client1
use IO::Socket;
my $sock = new IO::Socket::INET ( PeerAddr => 'xx.xx.xx.xx', PeerPort => '11050', Proto => 'tcp', );
die "Could not create socket: $!\n" unless $sock;
use POSIX 'strftime';
$time=strftime("%H%M%S",localtime) . "\n";
$date=strftime("%d%m%y",localtime)."\n";
$data="#00000##0#0000#AUT#1#V#07734.7000,E,1259.5355,N,000.00,288#$date#$time##";
print $data;
print $sock "$data";
close($sock);
command: bash script to execute
#!/bin/bash
#path: /bin/server
set PATH=/usr/bin/perl
export PATH
/home/nuthan/client1
#perl home/nuthan/client1
crontab command:
Run this socket client every 60 secs.
* * * * * server 2>&1 >> /var/log/client.log
Error: Finally, i get this Error!!!
No command 'bin' found, did you mean:
Command 'win' from package 'wily' (universe)
Command 'tin' from package 'tin' (universe)
Command 'bip' from package 'bip' (universe)
Command 'bing' from package 'bing' (universe)
Command 'bins' from package 'bins' (universe)
bin: command not found
WHERE AM I GOING WRONG!!!!? please help!!!
You should not set PATH to the perl executable but instead to the directories containing the tools you want to use, e.g.
export PATH=/bin:/usr/bin
#TLP Thanks for ur help. Got it working!!!
bash:
#!/bin/sh
set PATH=/usr/bin/perl
export PATH=/bin:/bin
/home/nuthan/clients/client1
cron command:
* * * * * /usr/bin/perl /bin/client1 2>&1 >> /home/nuthan/logs/client1.log
logging client # /home/nuthan/logs/client1.log
Related
I try to run headless Selenium on CentOS7:
# cat /etc/os-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.2 (Maipo)"
I installed Xvfb and run it as
# /usr/bin/Xvfb :99
I installed firefox:
# firefox -v
Mozilla Firefox 38.5.0
and run it to check if it can be run at all:
# export DISPLAY=:99
# firefox
This is the output:
# firefox
Xlib: extension "RANDR" missing on display ":99".
console.error:
[CustomizableUI]
Custom widget with id loop-button does not return a valid node
console.error:
[CustomizableUI]
Custom widget with id loop-button does not return a valid node
GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications.
Firefox seems to be running after that command:
# ps aux | grep firefox
root 29476 7.3 14.9 852356 152256 pts/3 Sl+ 10:30 0:03 /usr/lib64/firefox/firefox
EDIT
Yes, it's running. Taking screenshot from the Xvfb by
DISPLAY=:99 import -window root -crop 1264x948+0+0 /tmp/screenshot.jpg
I can see
Now the problematic part.
I installed Selenium Remote Driver for perl
# cpanm Selenium::Remote::Driver
Then I ran standalone selenium driver:
# java -jar selenium-server-standalone-2.49.0.jar
Now I run test script:
#!/usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new(browser_name=>'firefox');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
After 45 second I get error from the driver:
Could not create new session: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
at (eval 89) line 510.
Seems like firefox launched by the driver does not see DISPLAY environment variable. I try to add it from the script:
#!/usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;
$ENV{DISPLAY}=":99";
my $driver = Selenium::Remote::Driver->new(browser_name=>'firefox');
$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();
It does not help, the previous error remains.
What do I do?
EDIT2
I tried the current setup with Python. All works.
# pip install selenium
And used the following test script:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
f = open('ptn-sel.txt', 'w')
f.write(driver.title)
driver.close()
f.close()
I understand it's problem of Perl driver.... Any suggestions?
Is python using the standalone server or running firefox itself?
If perl is using the server and the server is spawning firefox then you need $DISPLAY set in the server processes environment not the script's environment. (By running export DISPLAY=:99; java -jar selenium-server-standalone-2.49.0.jaror similar.)
If you don't want to use the standalone server at all then Selenium::Firefox looks like it might be interesting.
I used Module::Starter to create the skeleton of a module, and one of the test files it creates ("t/00-load.t") looks like this:
#!perl -T
use 5.006;
use strict;
use warnings FATAL => 'all';
plan tests => 1;
BEGIN {
use_ok( 'My::Module' ) || print "Bail out!\n";
}
But when I run make && make test, this test fails because turning on taint mode ("perl -T") removes "." from #INC, so that My::Module is not found. I can see the value of turning on taint checking in general, but how am I supposed to then test this code? This is the error message that's output:
# Failed test 'use My::Module;'
# at t/00-load.t line 10.
# Tried to use 'My::Module'.
# Error: Can't locate My/Module.pm in #INC (#INC contains:
# /Library/Perl/5.16/darwin-thread-multi-2level
# /Library/Perl/5.16
# /Network/Library/Perl/5.16/darwin-thread-multi-2level
# /Network/Library/Perl/5.16
# /Library/Perl/Updates/5.16.2/darwin-thread-multi-2level
# /Library/Perl/Updates/5.16.2
# /System/Library/Perl/5.16/darwin-thread-multi-2level
# /System/Library/Perl/5.16
# /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level
# /System/Library/Perl/Extras/5.16) at (eval 4) line 2.
# BEGIN failed--compilation aborted at (eval 4) line 2.
This is on perl 5.16.1, with Module::Starter 1.62 and ExtUtils::MakeMaker 6.86. The skeleton was created with "module-starter --module=My::Module", so using defaults for everything else.
When the module is created with Module::Starter, which in turn relies on MakeMaker (or Module::Build), then all building and testing should be done via the provided Makefile (or Build file, if using Module::Build). I.e., with make && make test or ./Build && ./Build test.
Though there are many queries flowing around asking the same question. But here the error is thrown by apache instead of Perl.
I am trying to create an XML Response for the client on Mac OS X Mavericks and have written the perl script as follows:
#!/usr/bin/perl -wT
use lib '/opt/local/lib/perl5/site_perl/5.16.1/Geo';
use strict;
use CGI;
use Geo::Gpx;
open (FH, "/tmp/temp/file.txt") or print ("Unable to Open File");
my $gpx = Geo::Gpx->new;
my $cgi = CGI->new;
print $cgi->header(-type=>"text/gpx",-status=>"200 OK");
my $lon;
my #arr = <FH>;
foreach(#arr){
my %waypoints;
my $var = $_;
my #lat = split(/\s+/,$var);
##waypoints=split(/\s+/,$_);
$waypoints{$lat[0]}=$lat[1];
$waypoints{$lat[2]}=$lat[3];
$gpx->add_waypoint(\%waypoints);
}
my $xml = $gpx->xml;
print $xml;
open FILE, ">/tmp/temp/xmlfile.xml" or die $!;
print FILE $xml;
close (FILE);
close(FH);
For the apache to find the actual path of the Gpx.pm, I have used 'use lib' to show it the real path of the file.
Although this script is working perfectly on command line, my apache server is throwing the following error:
[Tue Nov 26 18:34:51 2013] [error] [client 127.0.0.1] Can't locate Geo/Gpx.pm in #INC
(#INC contains: /opt/local/lib/perl5/site_perl/5.16.1/Geo /Library/Perl/5.16/darwin-thread-multi-2level
/Library/Perl/5.16 /Network/Library/Perl/5.16/darwin-thread-multi-2level /Network/Library/Perl/5.16
/Library/Perl/Updates/5.16.2 /System/Library/Perl/5.16/darwin-thread-multi-2level /System/Library/Perl/5.16
/System/Library/Perl/Extras/5.16/darwin-thread-multi-2level /System/Library/Perl/Extras/5.16 .) at /Users/Rachit/Sites/temp.pl line 7.
[Tue Nov 26 18:34:51 2013] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at /Users/Rachit/Sites/temp.pl line 7.
I have used macports and have found searching through the Web that Mavericks has got perl 5.16 preinstalled. So apache may be using that and perl is using the macport installed libraries.
On checking the paths mentioned by apache error_log file as I posted above, I have copied Gpx.pm in one of the libraries installed in Geo Folder but still not getting it resolved.
On running 'which perl' The result
/opt/local/bin/perl
And 'which cpan' is giving
/opt/local/bin/cpan
Kindly fix this issue as I am not able to move forward because of this. And I am not so familiar with apache.
/opt/local/lib/perl5/site_perl/5.16.1/Geo should be /opt/local/lib/perl5/site_perl/5.16.1/ as it will append the complete module name (replacing :: with /) to each path to find the files.
Can anybody throw me a bone on this one?
Can't locate object method "new" via package "IO::Socket::SSL" at Services/IMAP/Client.pm line 136.
if ( $use_ssl ) {
135 require IO::Socket::SSL;
136 $imap = IO::Socket::SSL->new (
137 Proto => "tcp",
138 PeerAddr => $hostname,
139 PeerPort => $port,
140 Timeout => $timeout,
141 Domain => AF_INET,
142 )
143 or $self->log_(0, "IO::Socket::SSL error: $#");
144 }
It has been running fine for months, but after some upgrading; presumably perl, it started.
Perl version is: (v5.16.3) on RHEL5
$perldoc -lm IO::Socket::SSL
/usr/local/lib/perl5/site_perl/5.16.3/IO/Socket/SSL.pm
$perldoc -lm IO::Socket::INET
/usr/local/lib/perl5/5.16.3/i686-linux/IO/Socket/INET.pm
$perldoc -lm Net::SSLeay
/usr/local/lib/perl5/site_perl/5.16.3/i686-linux/Net/SSLeay.pm
Am I missing dependencies?
Any help would be greatly appreciated
These all return without errors.
[root#gw1 ]# perl -MIO::Socket::SSL -e1
[root#gw1 ]# perl -MIO::Socket::IP -e1
[root#gw1 ]# perl -MIO::Socket::INET6 -e1
[root#gw1 ]# perl -MIO::Socket::INET -e1
[root#gw1 ]# perl -MNet::SSLeay -e1
[root#gw1 ]#
IO::Socket::SSL will try to load other modules before it decides from which module to inherit. These are:
IO::Socket::IP
IO::Socket::INET6
IO::Socket::INET
Since you do have IO::Socket::INET installed, maybe one of the other two modules is making trouble?
A bit embarrassing, but I found the issue causing my problems:
The shebang in the files used were:
#!/usr/bin/perl (Using the vendor perl)
Whereas
#!/bin/env/ perl
or
#!/usr/bin/local/perl
Is needed for my non vendor perl installed version.
Adjust for platform.
To everybody who provided input, thanks!
I am using Perl and the Net::DBus module. I wrote a simple test program:
#!/usr/bin/perl
use strict;
use warnings;
package MyObj;
use Net::DBus::Exporter qw(org.example.Tao);
use base qw(Net::DBus::Object);
sub new {
my $class = shift;
my $service = shift;
my $self = $class->SUPER::new($service, '/MyObj');
bless $self, $class;
return $self;
}
dbus_method("Hello", ["string"]);
sub Hello {
return 'Hello';
}
package main;
use Net::DBus;
use Net::DBus::Reactor;
my $bus = Net::DBus->session;
my $service = $bus->export_service("org.example.Tao");
my $object = MyObj->new($service);
my $reactor = Net::DBus::Reactor->main();
$reactor->run();
return 0;
I am connecting by ssh and using:
Perl, v5.8.8 built for x86_64-linux-thread-multi
Linux example.com 2.6.32.19-0.2.99.17.22250fd-xen #1 SMP 2010-09-13 10:16:50 +0200 x86_64 x86_64 x86_64 GNU/Linux
CentOS release 5.4 (Final)
When I try to start my test.pl, I get the error:
org.freedesktop.DBus.Error.Spawn.ExecFailed:
Failed to execute dbus-launch to autolaunch D-Bus session
This error is raised by this line:
my $bus = Net::DBus->session;
Google hinted to me about dbus-launch. I executed yum install dbus-x11.
I try start my test code again and get error in the same line:
org.freedesktop.DBus.Error.Spawn.ExecFailed:
dbus-launch failed to autolaunch D-Bus session:
Autolaunch error: X11 initialization failed.
After read manuals, I detect that DBUS session daemon isn't started and my ENV var DBUS_SESSION_BUS_ADDRESS is empty:
[root#zion perl]# ps ax|grep dbus|grep -v grep
1019 ? Ss 0:00 dbus-daemon --system
Then I exec:
[root#zion perl]# dbus-launch --sh-syntax
DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-smHadq6yxV,guid=101ccd74fb75ae501485ed004e2a9043';
export DBUS_SESSION_BUS_ADDRESS;
DBUS_SESSION_BUS_PID=5037;
[root#zion perl]# ps ax|grep dbus|grep -v grep
1019 ? Ss 0:00 dbus-daemon --system
5037 ? Ss 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
But DBUS_SESSION_BUS_ADDRESS is same empty.
Question:
I need simple two Perl apps. The first app registers the dbus session service. Another app using my registered service. What is the best and correct way to do it in my environment?
First of all, you need to eval dbus-launch output. Like this:
$ env | grep DBUS
(empty output; no DBUS session bus launched yet)
$ eval `dbus-launch --sh-syntax`
(empty output; DBUS session bus started, output is evaluated to set shell vars)
$ env | grep DBUS
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ZkMjn6B47b,guid=85b2da814a8a061d4e7a55004e35b499
Second, you should consider how are you going to use your apps. Try to answer yourself these questions: why are you trying to bind to session bus (which is by definition a bus, associated with an interactive user session)? If this is a system-wide service, it should bind to system bus. If it is a user service, user session manager should take care of starting dbus session bus.