Perl

26K

Solutions

10K

Contributors

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects.  Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

I'm having a problem with looping through lines in a variable.  When I run the code, there's a test "print" to make sure I'm getting all I want, but then when I print the command that I want to run, it's not using the $line variable. Here's the piece of code I run:

for my $line ( $servDescUser ) {
        print( "$line\n" );    # <-- This works correctly
        print( "\n" );
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=group:$servDescGrp\"` ");
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=shadow:$line\"` ");   # <-This works on the first $line
        print( "`ssh $server ldapclient mod -a \"serviceSearchDescriptor=passwd:$line\"` ");   # <- This works on the first $line
}

Here are the results:

ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=GlobalUnix,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=Storage,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=TSM,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=BMC,ou=dynGroups,dc=ipaper,dc=com


`ssh unxgen01 ldapclient mod -a "serviceSearchDescriptor=group:cn=*,ou=Groups,dc=ipaper,dc=com
"` `ssh unxgen01 ldapclient mod -a "serviceSearchDescriptor=shadow:ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=GlobalUnix,ou=dynGroups,dc=ipaper,dc=com
ou=people,dc=ipaper,dc=com?sub?ismemberof=cn=Storage,ou=dynGroups,dc=ipaper,dc=com
0
Become a Certified Penetration Testing Engineer
LVL 13
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

I have this line, which works fine in ksh.

 ssh $lserver "su - oudadm -c 'nohup ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep uid'"

How can I rewrite this line Perl.  I'm trying to convert this ksh file to Perl.  I've tried several ways, but haven't found one that works. I've tried this:

system( "ssh $lserver \"su - oudadm -c ;nohup ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep $userid\"" );

and this:

system( "ssh $lserver ldapsearch -h localhost -p 1389 -D \"cn=Directory Manager\" -j ~/pwd-file -b \"dc=ipaper,dc=com\" \"objectclass=posixAccount\" |grep dn: |grep $userid" );




Thanks,
David
0
What's the best way to print a numbered list from an array?    Let's say I have this in an array:

DBA
HEWITT
INETSVC

I want to print it like this with an option of the operator choosing a number to make a selection:

1) DBA
2) HEWITT
3) INETSVC

Thanks!
David
0
Hello all,
I have a directory on my macOS that every single name has a .dns at the end if it. for example:
PPPDDC3_0.31.172.in-addr.arpa.dns

Is there a sek, awk, perl or something I can run to remove the .dns file extension and leave it at
PPPDDC3_0.31.172.in-addr.arpa
I dont care about preserving it, just change it all

They are located in this type dir structure
/work/CTS/PPPDDC3-Export

Thank you,
Rich
0
Hello Experts -

I have a PERL script on a Linux server which I use to do a one-way sync of data from one system to another. The process takes about nine to 12 minutes to complete. Currently I have a cron job that runs the sync script every 20 minutes, but I'd like to decrease that time frame so I can get as close to continuous as possible without having runs overlap. What would be the best approach for this?

1) Set up a cron to run the script every minute and at the start of the script see if there is another invocation currently running and die there if there is?

2) Put the whole script in to a giant loop which will run forever?

3) Something else?

I'm guessing #1 is the best option. If so, what's the best way to check to see if a copy of the script is running?

Thanks in advance for any help/guidance,
-matt
0
Hi expert

good day

Is there any example for reference that was generate in perl script to capture patching result or generate report.  

such as capture result to capture for the folowing;

Get yum report for Errata info - yum list-sec --security

Get yum list update packages-- yum list updates --security

exclude in vi/etc/yum.conf ( to get information before patch)

yum list-sec --security

yum list updates --security

Get List of updates packages

yum list updates --security

Get installed packages

yum list installed

Get Errata CVE and relate info

yum updateinfo info --security |grep "Update | D\|CVE\|Severity"

The end result will show in the attachment.
Patching-report-sample.xlsx
0
Would like to add this to my existing PERL script.  Project created mapping between a Manufacturing release version and a Business release version numbers.  Based on the Manufacturing release database schema file .e.g. db_AB_17.43.03, I want to map this back to the business version.  So, given the file “db_AB_17.43.03” I want to get the Business version.  All of this is laid out in a directory hierarchy like the following.

Window Directory hierarchy structure:

CM  
        Bus-Version  --  
                Manurf-Version    
                                           DB         db_AB_17.43.03
0
I am developing a marine position database system in Perl on a Centos 6.5 server.
Users can email position reports to my system.  
My Perl script automatically processes each position report email, and sends a reply email back to the sender, acknowledging receipt of their position report.
I have also been working with the Garmin inreach explroer iridium messenger for position reporting.
I can easily configure the Garmin to send an email to my system, and my system can process the email with the position information without any problems, and store the information in my database.   This works great, but I can not send a reply back to the Garmin acknowledging receipt of the Garmin position report.
Sending the reply email to an alternate email address does not work if the sender is remove, and does not have access to email.
I need to send reply message back to the Garmin as an sms text message from an SMS phone number address.
To configure this, the Garmin would need to send the position report as an sms text message to my system, and  my system would need to reply back to the Garmin with an sms message.
The Garmin inReach Explorer can send 160 character messages to either an email addresses or to ans sms cell phone number.
Because Garmin charges for sms and email text messages, Garmin blocks all direct emails to the Garmin inReach Explorer.
Garmin will accept an sms reply message to the Garmin.
Because of this logic, I would like to find a way to send and receive …
0
Hello,

I am running into some limitations (...by design) with the XenCenter and Xenserver (Citrix Hypervisor) the issue I am facing is that when I am using GFS2 with the shares storage drives the XenCenter (mananagement console) doesn't seem to calculate the free space that's available for that particular shared storage drive.

That being said, I am looking to get some assistance writing a quick script to check the available space on a drive or file system and email if the system free space is below 20%. I will run the script a chron job every hour.
0
i'm trying to learn how to use Switch in a perl program.  i get the error "can't locate Switch.pm in @INC(you may need to install he switch module)"
how do i install switch properly?

 #!/usr/bin/perl -w
# try to compare an input string to my name
 
use strict;
use 5.010;
use warnings;
use Switch;
 
say "what is your name";
my $fn = <STDIN>;
chomp ($fn);
say "your name is $fn";


switch ($fn){
    case "dan"      {  say "How are you doing today Danny?"}
    case "donna"    {  say "How are you doing today Donna?"}
    else            {  say "get off me"                    }
}

Open in new window

ex2018_05_08.txt
0
Introduction to Web Design
LVL 13
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Please recommend a Perl script that will return the latitude and and longitude for an address.
Please explain the pros and cons of signing up for a google api account to use their geo code api.
Are there any alternatives to google for obtaining a latitude and longitude for an address ?

Thanks,
Jim West
0
Hi, I am using a perl script to connect to my IMAP server and retrieve my unread messages. I am using Net::IMAP::Simple .. when I find an unread message, I get a full copy of the message. Here is part of my script:

for $i (@mylist) {
$msg = $server->get( $i );
print "Message Number $i contains:\n";
print "$msg\n";
$ret = `rm -f /tmp/msg.txt`;
open(TMP,"> /tmp/msg.txt");
print TMP "$msg";
close TMP;
$line1 = `grep "Subject: " /tmp/msg.txt`;
chomp($line1);

Open in new window


I can see the attachment in the "$msg" .. but this is what the attachment looks like:

Content-Type: image/jpeg; name="20190421_132835.jpg"
Content-Disposition: attachment; filename="20190421_132835.jpg"
Content-Transfer-Encoding: base64
Content-ID: <16a45e7d6e23c578d131>
X-Attachment-Id: 16a45e7d6e23c578d131

Content-Type: image/jpeg; name="20190421_132835.jpg"
Content-Disposition: attachment; filename="20190421_132835.jpg"
Content-Transfer-Encoding: base64
Content-ID: <16a45e7d6e23c578d131>
X-Attachment-Id: 16a45e7d6e23c578d131

Open in new window


The data for the JPEG follows after that.

I just downloaded that script to take a look at it. It is not doing exactly what I need to do, and the script has no documentation on how to use it and run it

What I'd like to do is to modify my script so that any attachments are downloaded into a folder.

Thanks!
0
I'm having some issues to get the values I need from some hash or hashes

I'm using a module of:
        use JSON qw( decode_json );
Then get a return of a reference using
       my $decoded = decode_json($json);

From the data structure I have in $decoded I need to get the values for
skuPartNumber
servicePlanName

But not getting the format right to pull these values.

Attached is an example of what the data structure looks like printing it out with Data Dumper

Can someone please show me how to pull these two values out.
test.txt
0
i have a text  file. it looks like:
==================================
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................
person's name. ......................text....................................

==================================

how do i open the file of names of people in a cemetery and return the text that goes with  ONLY that name in perl?
the file is a list of about 3000 people and the text is when they died and where they are buried.  any language will do
this but i'm trying to learn perl in ubuntu.
0
Hi
I have an unquoted CSV file that also has columns / cells with comas in
I need to fix it prior to ingesting into a database (This is it, it can't be generated properly)
 
I've wrote a short perl script isolate the rows with too many columns outputting the deliminator as a '|' pipe
I now need to edit the rest

Bringing the file into excel or open office calc can help to work out where the problems with each row is because you can see patterns in the data BUT totally messes up formatting like leading zeros and dates

Using a plane text editor keeps this formatting but is sole destroying looking at 100's lines of CSV data comparing with the spreadsheet  and error prone

Any one know of a CSV editor that can do both?

In 1 pane have an text /CSV editor  and as the deliminator  is removed or added dynamically updates a spreadsheet like interface so you can see instantly the column data lines up
0
Hello,  I have a perl script that I need it to look into a directory named mpl.  right now I run it but it does it for one file at a time. Sucks cause There are a few hundred. So If I can seek hellp to make my perl script open a whole directory and do what it does per one file but in a whole directory.

I need my script adjusted  to look into my directory mpl and read all the zonefiles and change the serial number using date with an extra number 2019011300 ; serial for example

I run the script like this on the below:

./zonechanges.pl db.apptoapp.net.new vipchange

Copy of the script:

#!/usr/bin/perl

open(ZONE,  $ARGV[0]) || die "Zone file error $!";
while ( $line = <ZONE> ) {
        chomp $line;
        push @fileLines, $line;
}
close ZONE;



# Assuming simple CSV of old_ip, new_ip
open(IPMAP, $ARGV[1]) || die "IP Map file error: $!";
while ( $line = <IPMAP> ) {
        chomp $line;
        ($old, $new) = split(/,/, $line);
        $old =~ s/\s+//;
        $new =~ s/\s+//;
        $ip{$old} = $new;
}
close IPMAP;


## For every line
for ($count=0; $count < @fileLines; $count++) {
#       print STDERR "OUTER FOR ($count)\n";
        $line = $fileLines[$count];
#       print STDERR "OUTER FOR have line $line\n";
        ## For every old address in the remap
        for $old (keys(%ip)) {
                #print STDERR "INNER FOR ($old)\n";
                ## If the line matches the old address
                if ( $line =~ /$old/ ) {
                       

Open in new window

0
I ran a web app on a EC2 instance, which is using port 3003. But it  cannot be accessed from external network

With logged in with SSH, I curled 'localhost:3003', then response returned as expected.

WAF: Mojolicious
App start command: morbo "http://*:3003" myapp.pl

This is obviously insufficient configuration on web server, but I don't know how.

I am grateful if you could advise me.
0
i'm using ubuntu 18.04 and i am trying to learn perl and get a window to appear like visual studios where i can create buttons and drop-down boxes, etc and i cannot seem to gt it installed.  i used https://www.perl.com/pub/2001/03/gui.html/ and i cannot get their examples:ptked and ptksh to execute.  these are listed in the paragraph right above: pTk Core Concepts.  is there a better example or do you see what i'm missing?
0
I wrote a CGI in perl a long ago (never wrote perl script for ten years ;-). It is  named "check.cgi" in the www/cgi-bin directory (i.e. www/cgi-bin/check.cgi)

It starts as follows:

#!/usr/bin/perl
use strict;
use CGI;
our $mailprog        = "/usr/sbin/sendmail -t";
our $respond         = "";
our $upto            = "";
our $data            = '';
our $db              = '';

# -----------------------------------------------------------------------------
# declare base
# -----------------------------------------------------------------------------
our @token;
our $q  = new CGI;
our %in = $q->Vars;
our %gp;

# -----------------------------------------------------------------------------
# get the inputs
# -----------------------------------------------------------------------------
our $dn       =lc($in{'dn'       }) || ''         ;
our $orig     =lc($in{'orig'     }) || ''         ;
our $tld      =lc($in{'tld'      }) || ''         ;

Open in new window

.....

Which URL should be entered to trigger it : "http://abc.de/...."  what the "...." should be ?

Thanks a lot !
0
Learn SQL Server Core 2016
LVL 13
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I'm trying to "POST" data via jquery ajax to a back end perl script

If i change bellow method to GET it works

HTML
<html>
  <head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
         <script>
           var url = "cgi-bin/form.pl?list=123,456,789&foo=bar";
           $(function() {
           $("#PostBtn").click(function(){
            $.ajax({
            url: url, 
            type:"POST",
            dataType:"text",
            success: function(data, textStatus, jQxHr) {
            
            $("#res").html(data);
            },
            });
              });
          });
         </script>
  </head>
  <body>
    <div><button id="PostBtn" value="Post btn">Post btn</button></div>
    <div id="res"></div>
  </body>
</html>

Open in new window


cgi-bin/form.pl
#!C:\strawberry\perl\bin\perl.exe
print "Content-type:text/html\n\n";

use CGI;
 my $query = CGI->new;

my @Names = $query->param;
my $list = $query->param('list');
my $foo = $query->param('foo');

<p>data $data</data>
print <<HTML;
  <h1>Hello Posts</h1>
HTML
foreach my $name (@Names)
  {
    print "<p>" . $name . "[ " . $q->param($name) . "]</p>";  
    
  }

Open in new window


How do I receive the parameters in perl?
0
Hello,
I use ActivePerl on WIN7.
I've found a useful script for converting ANSI to UTF8 (call it utf8.pl):

use File::Slurp;
use Encode;

$File_Name="c:\\dottorandi.xml";
$file_con=read_file($File_Name);

open (OUT, ">c:\\dottorandiUTF8.xml");
print OUT encode('utf8', $file_con);
close OUT;

Open in new window


but I'd like to use NOT fixed paths to the file to convert (like c:\\dottorandi.xml) but the STDIN and STDOUT, so I can call the script from the command line like:
perl utf8.pl<fileANSI.xml>fileUTF8.xml

Open in new window

I've try to use:
$File_Name=<STDIN>;
...
open (OUT, <STDOUT>);

Open in new window

but without luck.
Where's my error?
Thanks,
Fabiano
0
what is wrong with my syntax of this short perl hash program:
===================================================================
#!/usr/bin/perl;                                           # ex4_3
use warnings;
use strict;
use 5.010;
my $family_name{"fred"}="flintstone";

Open in new window

===================================================================
~                                                                                                                                                                        
~     sorry but your web site would not let me attach that file...
0
i'm new to perl so this is hopefully simple.  i keep getting the following error:

------------------------------------------------------------------------------------------------------------
syntax error at /home/dwcronin/programs/ex4_1 line 7, near "$family_name{"
Execution of /home/dwcronin/programs/ex4_1 aborted due to compilation errors.
--------------------------------------------------------------------------------------------------------------

specifically. i'm trying to learn hashes by following the o'reilly book 'learning perl" by randal schwartz.
0
Hi

How do I truncate a string to a maximum length but at a white space?
I know substr(0,15) would work but I don't want to end in the middle of a word

the result of the code bellow should be $ShortString  = "Lorem ipsum" because the 15th character is the "l" in dolor!

In reality the length  would be 150 but it's easier to count 15 characters

Once I have $ShortString  this will form part of a URL do I need escape it?

So
 

<a href="$http://example.com?foo=bar&mystring=$ShortString>My Link</a>
 

my $LongString="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas fermentum, nunc in vestibulum lobortis, sapien dui aliquam risus, vitae tincidunt risus augue id dolor. Nullam.";

my $len = length($LongString);

print "Lenth of LongString = $len\n";

my $ShortString;

if ($len > 15){
    ($ShortString) = $LongString =~ m/^(.*[15])?<=\b/
}
else{
    $ShortString = $LongString
}
print "ShortString = $ShortString\n";

Open in new window

0
what is the perl regular expresssion to compare "machinename\\username" in perl scripts?

sample code:
print "Hello World!\n";
$mname="BVM";
$user = "test";
$mu_reg = "^(?i)$mname/\/\$user \$";
$mu_str = "164AUTH/\/\chris";



$ipstr="$mu_str ";
$ipstr_re = "^(?i)mu_reg \$"; # regex failed with two backslashes. How to fix it?
if ($ipstr !~ /$ipstr_re/) {
    print "It doesn't match\n";
}
else {
    print "It matches\n";
}
0

Perl

26K

Solutions

10K

Contributors

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects.  Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

Top Experts In
Perl
<
Monthly
>