A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

ssh debug3: Incorrect RSA1 identifier debug3: Could not load ".ssh/id_rsa" as a RSA1 public key

When testing ssh with -vvv, you see this in the log:

    debug3: Incorrect RSA1 identifier
    debug3: Could not load ".ssh/id_rsa" as a RSA1 public key

This is not an error.
This is not the problem you're looking for.
Your problem is something else.

(source)

See also another ssh non-error.

debug2: key_type_from_name: unknown key type '-----BEGIN'

SSH debug output can be quite misleading.
When you see the following output, it does NOT indicate a problem.

debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
...
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/foo/.ssh/id_rsa type 1

The final line tells you that the key was read successfully.

(source)

See also another ssh non-error.

Useful bash flags for scripts verbose trace expand error exit

Useful flags:
set -v # "verbose" - echo commands
set -x # "xtrace" - like verbose but expands commands
set -e # "errexit" - abort script at first error
set -u # "nounset" - strict mode: undefined variable causes an exit

Long format:
set -o verbose

Bash "strict mode":
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

Windows: folder or file open in another program

When you try to move a folder:

    "The action can't be completed because the folder or a file in it is open in another program"

This stunningly unhelpful error message has persisted through many versions of Windows.

The way I work around it is:

  • Rename an unrelated file or folder nearby, then rename it back again.
  • The original folder or file should now be "unlocked"
You can always reboot to fix it, too.

SSH warning: authenticity of host can't be established

Problem

The authenticity of host 'example.com (1.2.3.4)' can't be established.
RSA key fingerprint is ab:cd:ef:12:34:56:78:90:ab:cd:ef:12:34:56:78:90
Are you sure you want to continue connecting (yes/no)?

Solution

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no

Make sure you understand the security implications of doing this (Hint: they're not good).

(source)

Cannot scp, but ssh works fine

Maybe your .bashrc or similar prints something to the console? This breaks scp.

e.g. if .bashrc or something it calls contains:
echo "Welcome to the server"

Then scp will just print "Welcome to the server" and not even attempt to copy the file.

sudo: no tty present and no askpass program specified

How to run sudo on a remote machine:

ssh user@domain.com 'sudo echo "foobar"'

Error:
    sudo: no tty present and no askpass program specified

Solution:

 ssh -t user@domain.com 'sudo echo "foobar"'

(source)

Perl MooseX::Params::Validate gotcha

This error:

Parameter #1 ("1") to Some::Module::a_method did not pass the \'checking type constraint for Different::Module\' callback\n at /some/path/to/some/file/or/other.pm line 42

(but the parameters passed in are actually all correct)

...it could mean you forgot to shift off $self. pos_validated_list doesn't detect $self like validated_list and validated_hash do.

Can't push to github




The problem:

Git asks you for your password, when it should just accept your SSH key.

$ git push origin master
Password for 'https://github@github.com': 


The solution:

1) First, read the github documentation to ensure your SSH keys are set up correctly

2) Then add this to your ~/.ssh/config:

Host github github.com
Hostname github.com
User git
IdentityFile ~/.ssh/github/id_rsa


3) Finally, clone using ssh instead of https:

git clone https://github.com/username/project-name.git # wrong

git clone git@github.com:username/project-name.git # right

4) Push should now work as expected


Why doesn't smbclient work?

Symptoms:
You can mount a NetApp 'shared drive' using the mount program fine.
But if you try to browse it using smbclient, you get this error when it fails to connect:
session setup failed: NT_STATUS_MORE_PROCESSING_REQUIRED

Cause:
A bug in Ubuntu 11.04

Workaround:
Change your hostname to a short string, without any hypens (dashes) in it!

(copy)

Run an external command from Perl, capturing both the output and the exit value


# This is how to run an external command from Perl,
# capturing both the output and the exit value

sub run_external_command {
    my ($self, $command) = @_;
    $self->logger->debug("Running command: $command");

    my $output = '';
    $command .= ' 2>&1 | '; # capture all output
    open(my $capture, $command);
    {
        local $/ = undef;
        $output = <$capture>;
    }
    close($capture);
    chomp($output);

    my $exit_value = ${^CHILD_ERROR_NATIVE} >> 8;
    $self->logger->debug("Exit value of command: '$exit_value'");
    $self->logger->debug("Output of command: '".($output || '[no output]')."'");

    return ($exit_value, $output);
}

This is another way:

use IPC::Open3;

sub run_external_command_2 {
  local (*my_in, *my_out, *my_err);

  my $command = "some command here that might error";
  my $pid = open3(\*my_in, \*my_out, \*my_err, $command) or die($!);

  close(my_in);
  my $std_out = do { local $/; };close(my_out);
  my $std_err = do { local $/; };close(my_err);

  waitpid($pid, 0);
  my $exit_code = $? >> 8;

  return { exit_code => $exit_code, std_out => $std_out, std_err => $std_err };
}

Rollback within a txn_do for DBIC


try {
    $self->schema->txn_do(sub {
        # something went bad
        die 'argh';
    });
}
catch ($e) {
    # log me
    # no roll back needed
}

Always get a stack trace when Perl dies

Always get a stack trace when Perl dies or warns:

use Carp::Always;
or

perl -MCarp::Always -e'die "argh"'


Know if output is being captured in Perl

if (-t STDERR) {
    print "standard error is not being captured (it's going to the terminal)\n";
    # email the error
}
else {

    print "standard error IS being captured\n";
    # just print the error
}

Get a full backtrace upon Perl error

$SIG{__DIE__} = \&confess;

Log and email your Apache errors

In the .htaccess at the root of the site:
ErrorDocument 404 http://www.example.com/error_page.php?err=404
ErrorDocument 503 http://www.example.com/error_page.php?err=503
etc.

In error_page.php:


$myemail = "someone@example.com";
$subject = "example.com: $errorNum error";
$message = "$errorNum Error Report:\n";
$message .= "\nHTTP_REFERRER: ".$_SERVER['HTTP_REFERER'];
$message .= "\nREQUEST_URI: ".$_SERVER['REQUEST_URI'];
$message .= "\nHTTP_USER_AGENT: ".$_SERVER['HTTP_USER_AGENT'];
$message .= "\nQUERY_STRING: ".$_SERVER['QUERY_STRING'];
$message .= "\nREMOTE_ADDRESS: ".$_SERVER['REMOTE_ADDR'];


ob_start();
print "\n\nSERVER = "; print_r( $_SERVER );
print "\nGET = "; print_r( $_GET );
print "\nPOST = "; print_r( $_POST );
print "\nFILES = "; print_r( $_FILES );
print "\nREQUEST = "; print_r( $_REQUEST );
print "\nSESSION = "; print_r( $_SESSION );
print "\nENV = "; print_r( $_ENV );
print "\nCOOKIE = "; print_r( $_COOKIE );
print "\nprevious php_errormsg = "; print_r( $php_errormsg );
print "\nargv = "; print_r( $argv );
$output = ob_get_clean();
$message .= "\n\n$output\n";


# email the error
mail($myemail,$subject,$message,"From: support@example.com");


# log the error
$myFile = "logs/error.".date('Y_m_d-H.i.s').".log";
$fh = fopen($myFile, 'w');
$stringData = $message;
fwrite($fh, $stringData);
fclose($fh);
?>

Debugging XSLT

...is not fun:

<!-- DEBUG -->
<xsl:if test="$debug">
<xsl:message><xsl:text>--------</xsl:text></xsl:message>
<xsl:message><xsl:text>FUNCTION display-pagination-links:</xsl:text></xsl:message>
<xsl:message><xsl:text>--------</xsl:text></xsl:message>
<xsl:message><xsl:text>direction: </xsl:text><xsl:value-of select="$direction"/></xsl:message>
<xsl:message><xsl:text>link_type: </xsl:text><xsl:value-of select="$link_type"/></xsl:message>
</xsl:if>

Apache error "premature EOF in parsed file"

When Apache 1.3 says "premature EOF in parsed file".
What it means is "You've messed up the attribute syntax in a mod_include command".

Examples:

<!--#config timefmt=%s --> (no quotes)

<!--#set var='title' value='This title would've screwed things up' --> (apostrophe not escaped)

Can't connect to MySQL

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Reason: mysqld is not running!

is reserved

While attempting to read the filehandle that you think points to a file, you get this error:

Modification of a read-only value attempted

Maybe this means the script is reading from the inline __DATA__ section, and you're trying to write to it?