2023.03.11 04:26 East-Barnacle-7473 My Timer script
#!/usbin/perl #timers.pl #This is perl 5, version 32, subversion 1 (v5.32.1) #built for amd64-openbsd use warnings; use strict; # Store User Seconds my $Seconds = ""; # Store System String my $cmdString = ""; # How many timers do you want get input print "How Many Timers:"; my $timers =I was using perlfaq8(1) background process exhausted my search for a answer. I asked reddit then realized; for(my $i = 1; $i <= $timers ; $i++){ # How many Seconds for Timer get user input print "\nHow Many Seconds for Timer $i:"; $Seconds = ; print $Seconds; # Remove any NewLines or Cartage Returns # Tailing '&' isn't on a newline causes a sh error $Seconds =~ s/\n//g; $Seconds =~ s/\/g; # Command String to pass to system $cmdString = "perl ~/perls/timer.pl $i $Seconds &\n"; system($cmdString); }
#!/usbin/perl #timer.pl #This is perl 5, version 32, subversion 1 (v5.32.1) use warnings; use strict; # Set Autoflush Realtime not Endline for print # Not needed for this silent example #local $ = 1; # Check Argument total that were passed # $#ARG, $ARGV[0], $ARGV[1], is a perl variable if($#ARGV < 1){ print "Error 1: Timer Name or Timer Seconds Not Set"; }else{ #Call Sub timer #1st Argument is Timer Name #2nd Argument Timer Seconds timer($ARGV[0],$ARGV[1]); } sub timer{ # Hold Elapsed Seconds my $ElapsedTime = 0; # Set Start Time my $StartTime = time(); my $CurrentTime = time(); #Compare ElapsedTime to Second Argument(Total Seconds) while($ElapsedTime <= $_[1]) { #Update only on seconds have changed #Helps with printing so no duplicate numbers if($ElapsedTime != ($CurrentTime - $StartTime)) { # Unremark to Print a number of passed Seconds, except 0 #if($ElapsedTime != 0){print "(",$ElapsedTime,")";} $ElapsedTime = $CurrentTime - $StartTime; } # Update Current Time $CurrentTime = time(); } # Print Timer Name End Status print "\n\n***Timer $_[0] has ended***\n\n"; return 0; }I am a hobbyist not a expert just goofing off. I recommend learning from briandfoy.
2019.02.17 20:35 ronasimi How to strip characters from perl script output?
2017.10.13 14:49 Klousk Problem with Postfix randomizer
#!/usbin/perl -w # author: Hari Hendaryantouse strict; use warnings; use Sys::Syslog qw(:DEFAULT setlogsock); use List::Util::WeightedRoundRobin; use Storable; my $hashfile="/tmp/file.hash"; store {}, $hashfile unless -r $hashfile; # # our transports lists, we will define this in master.cf as transport services # Queued using Weighted Round-Robin Scheduling # my $list = [ { name => 'smtp1:', weight => 5, }, { name => 'smtp2:', weight => 5, }, { name => 'smtp3:', weight => 5, }, { name => 'smtp4:', weight => 5, }, { name => 'smtp5:', weight => 5, }, { name => 'smtp6:', weight => 5, }, { name => 'smtp7:', weight => 5, }, { name => 'smtp8:', weight => 5, }, { name => 'smtp9:', weight => 5, }, { name => 'smtp10:', weight => 5, }, ]; my $WeightedList = List::Util::WeightedRoundRobin->new(); my $weighted_list = $WeightedList->create_weighted_list( $list ); # $maxinqueue max number of queue in smtp list my $maxinqueue = scalar(@{$weighted_list}); # # Initalize and open syslog. # openlog('postfix/randomizer','pid','mail'); # # Autoflush standard output. # select STDOUT; $++; while (<>) { chomp; my $count; eval { retrieve($hashfile) }; my $hash = ($@ ? {} : retrieve($hashfile)); if (!defined $hash->{"index"}) { $count = 0; } else { $count = $hash->{"index"}; } if ($count >= $maxinqueue) { $hash->{"index"} = 0; $count = 0; } $hash->{"index"}++; store $hash, $hashfile; my $random_smtp = ${$weighted_list}[$count]; if (/^get\s(.+)$/i) { print "200 $random_smtp\n"; syslog("info","Using: %s Transport Service", $random_smtp); next; } print "200 smtp:\n"; }
2016.01.29 21:37 myhusbandclaims Can someone help translate this perl script into js?
#!/usbin/perl -w # # Based on # http://forums.ninjablocks.com/index.php? # p=/discussion/2931/aldi-remote-controlled-power-points-5-july-2014/p1 # and # http://pastebin.ca/2818088 # and # https://github.com/franc-cartebauhn-wifi/blob/mastebauhn.pl # # Tuned for Orvibo S20 by Branislav Vartik use strict; use IO::Socket; use IO::Select; use Data::Dumper; use Net::Ping; use Net::ARP; my $debug = 1; # Change this to 0 to avoid debug messages my $port = 10000; my $fbk_preamble = pack('C*', (0x68,0x64,0x00,0x1e,0x63,0x6c)); my $ctl_preamble = pack('C*', (0x68,0x64,0x00,0x17,0x64,0x63)); my $ctl_on = pack('C*', (0x00,0x00,0x00,0x00,0x01)); my $ctl_off = pack('C*', (0x00,0x00,0x00,0x00,0x00)); my $twenties = pack('C*', (0x20,0x20,0x20,0x20,0x20,0x20)); my $onoff = pack('C*', (0x68,0x64,0x00,0x17,0x73,0x66)); my $subscribed = pack('C*', (0x68,0x64,0x00,0x18,0x63,0x6c)); sub findS20($) { my ($mac) = @_; my $s20; my $reversed_mac = scalar(reverse($mac)); my $subscribe = $fbk_preamble.$mac.$twenties.$reversed_mac.$twenties; my $socket = IO::Socket::INET->new(Proto=>'udp', LocalPort=>$port, Broadcast=>1) die "Could not create listen socket: $!\n"; $socket->autoflush(); my $select = IO::Select->new($socket) die "Could not create Select: $!\n"; my $iaddr = inet_aton($ARGV[0]) die 'Unable to resolve'; my $to_addr = sockaddr_in($port, $iaddr); $socket->send($subscribe, 0, $to_addr) die "Send error: $!\n"; my $n = 1; while($n <= 3) { print "DEBUG: Waiting for status $n\n" if $debug; my @ready = $select->can_read(1); foreach my $fh (@ready) { my $packet; my $from = $socket->recv($packet,1024) die "recv: $!"; if ((substr($packet,0,6) eq $subscribed) && (substr($packet,6,6) eq $mac)) { my ($port, $iaddr) = sockaddr_in($from); $s20->{mac} = $mac; $s20->{saddr} = $from; $s20->{socket} = $socket; $s20->{on} = (substr($packet,-1,1) eq chr(1)); return $s20; } } $n++; } close($socket); return undef; } sub controlS20($$) { my ($s20,$action) = @_; my $mac = $s20->{mac}; if ($action eq "on") { $action = $ctl_preamble.$mac.$twenties.$ctl_on; } if ($action eq "off") { $action = $ctl_preamble.$mac.$twenties.$ctl_off; } print $action,"\n"; my $select = IO::Select->new($s20->{socket}) die "Could not create Select: $!\n"; my $n = 0; while($n < 2) { $s20->{socket}->send($action, 0, $s20->{saddr}) die "Send error: $!\n"; my @ready = $select->can_read(0.5); foreach my $fh (@ready) { my $packet; my $from = $s20->{socket}->recv($packet,1024) die "recv: $!"; my @data = unpack("C*", $packet); my @packet_mac = @data[6..11]; if (($onoff eq substr($packet,0,6)) && ($mac eq substr($packet,6,6))) { return 1; } } $n++; } return 0; } my $usage = "Usage: $0\n"; print "arguments: \t$#ARGV \t"; ($#ARGV == 1) die $usage; my $ip = $ARGV[0]; my $command = $ARGV[1]; my $TargetMac = Net::ARP::arp_lookup("eth0",$ip); my @mac = split(':',$TargetMac ); # my @mac = split('.', $ARGV[1]); ($#mac == 5) die $usage; @mac = map { hex("0x".$_) } split(':', $TargetMac); my $mac = pack('C*', @mac); my $n = 1; my $p = Net::Ping->new('icmp', 1); do { print "DEBUG: Ping $n\n" if $debug; ( $n == 10 ) && die "Could not ping S20 with IP of $ip\n"; $n++; } until ($p->ping($ip)); $p->close(); my $s20 = findS20($mac); unless (defined($s20)) { print "DEBUG: Sleeping for retry\n" if $debug; sleep(1); $s20 = findS20($mac); defined($s20) die "Could not find S20 with mac of $mac\n"; } if ($command eq "status") { print $s20->{on} ? "on\n" : "off\n"; exit(0); } ($command ne "on" && $command ne "off") && die $usage; for(my $n=1; $n<=3; $n++) { print "DEBUG: Waiting for confirmation $n\n" if $debug; controlS20($s20, $command) && exit(0); # FIXME: Print DEBUG info } die "Could not change S20 to $command\n";
2016.01.29 21:23 myhusbandclaims Can someone help translate this perl script into js?
#!/usbin/perl -w # # Based on # http://forums.ninjablocks.com/index.php? # p=/discussion/2931/aldi-remote-controlled-power-points-5-july-2014/p1 # and # http://pastebin.ca/2818088 # and # https://github.com/franc-cartebauhn-wifi/blob/mastebauhn.pl # # Tuned for Orvibo S20 by Branislav Vartik use strict; use IO::Socket; use IO::Select; use Data::Dumper; use Net::Ping; use Net::ARP; my $debug = 1; # Change this to 0 to avoid debug messages my $port = 10000; my $fbk_preamble = pack('C*', (0x68,0x64,0x00,0x1e,0x63,0x6c)); my $ctl_preamble = pack('C*', (0x68,0x64,0x00,0x17,0x64,0x63)); my $ctl_on = pack('C*', (0x00,0x00,0x00,0x00,0x01)); my $ctl_off = pack('C*', (0x00,0x00,0x00,0x00,0x00)); my $twenties = pack('C*', (0x20,0x20,0x20,0x20,0x20,0x20)); my $onoff = pack('C*', (0x68,0x64,0x00,0x17,0x73,0x66)); my $subscribed = pack('C*', (0x68,0x64,0x00,0x18,0x63,0x6c)); sub findS20($) { my ($mac) = @_; my $s20; my $reversed_mac = scalar(reverse($mac)); my $subscribe = $fbk_preamble.$mac.$twenties.$reversed_mac.$twenties; my $socket = IO::Socket::INET->new(Proto=>'udp', LocalPort=>$port, Broadcast=>1) die "Could not create listen socket: $!\n"; $socket->autoflush(); my $select = IO::Select->new($socket) die "Could not create Select: $!\n"; my $iaddr = inet_aton($ARGV[0]) die 'Unable to resolve'; my $to_addr = sockaddr_in($port, $iaddr); $socket->send($subscribe, 0, $to_addr) die "Send error: $!\n"; my $n = 1; while($n <= 3) { print "DEBUG: Waiting for status $n\n" if $debug; my @ready = $select->can_read(1); foreach my $fh (@ready) { my $packet; my $from = $socket->recv($packet,1024) die "recv: $!"; if ((substr($packet,0,6) eq $subscribed) && (substr($packet,6,6) eq $mac)) { my ($port, $iaddr) = sockaddr_in($from); $s20->{mac} = $mac; $s20->{saddr} = $from; $s20->{socket} = $socket; $s20->{on} = (substr($packet,-1,1) eq chr(1)); return $s20; } } $n++; } close($socket); return undef; } sub controlS20($$) { my ($s20,$action) = @_; my $mac = $s20->{mac}; if ($action eq "on") { $action = $ctl_preamble.$mac.$twenties.$ctl_on; } if ($action eq "off") { $action = $ctl_preamble.$mac.$twenties.$ctl_off; } print $action,"\n"; my $select = IO::Select->new($s20->{socket}) die "Could not create Select: $!\n"; my $n = 0; while($n < 2) { $s20->{socket}->send($action, 0, $s20->{saddr}) die "Send error: $!\n"; my @ready = $select->can_read(0.5); foreach my $fh (@ready) { my $packet; my $from = $s20->{socket}->recv($packet,1024) die "recv: $!"; my @data = unpack("C*", $packet); my @packet_mac = @data[6..11]; if (($onoff eq substr($packet,0,6)) && ($mac eq substr($packet,6,6))) { return 1; } } $n++; } return 0; } my $usage = "Usage: $0\n"; print "arguments: \t$#ARGV \t"; ($#ARGV == 1) die $usage; my $ip = $ARGV[0]; my $command = $ARGV[1]; my $TargetMac = Net::ARP::arp_lookup("eth0",$ip); my @mac = split(':',$TargetMac ); # my @mac = split('.', $ARGV[1]); ($#mac == 5) die $usage; @mac = map { hex("0x".$_) } split(':', $TargetMac); my $mac = pack('C*', @mac); my $n = 1; my $p = Net::Ping->new('icmp', 1); do { print "DEBUG: Ping $n\n" if $debug; ( $n == 10 ) && die "Could not ping S20 with IP of $ip\n"; $n++; } until ($p->ping($ip)); $p->close(); my $s20 = findS20($mac); unless (defined($s20)) { print "DEBUG: Sleeping for retry\n" if $debug; sleep(1); $s20 = findS20($mac); defined($s20) die "Could not find S20 with mac of $mac\n"; } if ($command eq "status") { print $s20->{on} ? "on\n" : "off\n"; exit(0); } ($command ne "on" && $command ne "off") && die $usage; for(my $n=1; $n<=3; $n++) { print "DEBUG: Waiting for confirmation $n\n" if $debug; controlS20($s20, $command) && exit(0); # FIXME: Print DEBUG info } die "Could not change S20 to $command\n";
2015.03.07 01:27 ccie6861 Perl appears to be processing out of order. Help.
185 $telnet->clear_accum(); 186 print $telnet "\r"; 187 unless ($telnet->expect(30,"$device_prompt")) { print $telnet->exp_before(); die; } 188 189 if($auto_save) { 190 print $telnet "write memory\r"; 191 unless ($telnet->expect(30,"$device_prompt")) { die; } 192 } 192 194 print $telnet "exit\r";output:
SWITCH# SWITCH#write memory Building configuration... [OK] SWITCH#exit Connection to 10.1.1.1 closed. exit Connection to 10.1.1.1 closed. Died at ./port_by_mac.pl line 187.New debug output:
Starting EXPECT pattern matching... at /uslib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x92d3f08)', 30, 'LESSW17#') called at ./port_by_mac.pl line 196 main::get_port(10.8.0.17, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 185 main::get_port(10.8.0.18, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 185 main::get_port(10.8.0.1, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 89 LESSW17#write memory Building configuration... [OK] LESSW17#Starting EXPECT pattern matching... at /uslib/perl5/site_perl/5.8.8/Expect.pm line 561 Expect::expect('Expect=GLOB(0x92d3f08)', 30, 'LESSW17#') called at ./port_by_mac.pl line 196 main::get_port(10.8.0.18, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 185 main::get_port(10.8.0.1, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 89 exit Connection to 10.8.0.17 closed. Closing spawn id(4). at /uslib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x92d3f08)') called at /uslib/perl5/site_perl/5.8.8/Expect.pm line 894 Expect::_multi_expect(30, 'undef', 'ARRAY(0x92d4124)') called at /uslib/perl5/site_perl/5.8.8/Expect.pm line 565 Expect::expect('Expect=GLOB(0x92d3f08)', 30, 'LESSW17#') called at ./port_by_mac.pl line 196 main::get_port(10.8.0.18, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 185 main::get_port(10.8.0.1, '08ea.447e.2e40', 'AH-7e2e40') called at ./port_by_mac.pl line 89 spawn id(4) closed. exit Connection to 10.8.0.17 closed. Died at ./port_by_mac.pl line 197. Closing spawn id(4). at /uslib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0x92d3f08)') called at /uslib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0x92d3f08)') called at ./port_by_mac.pl line 0 eval {...} called at ./port_by_mac.pl line 0The output pretty clearly suggests that the "print exit" command on line 194 is being executed before the unless is evaluated on line 187.