Tuesday, December 22, 2009

SFTP Message: Received message too long

Using sftp to access a remote server I had access to, I was presented with the below error message:
  prystasj@prystasj:~/workspace$ sftp somehost
Received message too long 1231953966
prystasj@prystasj:~/workspace$
However, I was able to ssh just fine:
  prystasj@prystasj:~/workspace$ ssh somehost
In .bashrc
In .bash_profile
prystasj@somehost:~$
The key was that my login scripts, .bashrc and .bash_profile produced output as shown above, which was intentional as I was trying to once demonstrate the difference between a login and non-login shell to myself to see which files were sourced. After removing the output-producing commands from the files, I was able to sftp like normal.

Sunday, December 6, 2009

Answering Yes to Prompts Automatically

The yes command can be used to pipe a series of y's to another command, so that the user does not have to wait to be prompted during the command's execution.

For example, after a Linux install, I went to use CPAN for the first time to install the File::Find::Rule module.

  prystasj@prystasj:~$ cpan -i "File::Find::Rule"

CPAN is the world-wide archive of perl resources.
...
Would you like me to configure as much as possible automatically? [yes]
While answering yes above will configure CPAN automaticaly, I'll still be prompted to answer questions regarding the module's dependencies:
  Writing Makefile for File::Find::Rule
Falling back to other methods to determine prerequisites
---- Unsatisfied dependencies detected during ----
---- RCLAMP/File-Find-Rule-0.32.tar.gz ----
Number::Compare [requires]
Text::Glob [requires]
Shall I follow them and prepend them to the queue of modules
we are processing right now? [yes]
To automatically answer yes to every question, you can pipe the output of the yes command to the prompting command. For example:
  prystasj@prystasj:~$ yes | cpan -i "File::Find::Rule"
Now I can install the module without watching the command's progress.

Tuesday, December 1, 2009

Groovy: Retrieving XML Element Attributes in a Map

The Groovy script below is a little test I came up to help me remember how to grab element attributes from an XML document. In the example message, I want the attributes from the request element in a Map:
  def message = """<message>
<request file="/home/prystasj/file.txt" type="txt" />
<message>"""

def xml = new XmlParser().parseText(message)
def attrs = xml.request[0].attributes()

println "Class: ${attrs.getClass().getName()}"
println "Size: ${attrs.size()}"
println "Attributes: $attrs"
println "File: ${attrs.file}"
println "Type: ${attrs.type}"

The key that tripped me up was that I needed to grab the first request element (indexed at 0) in the assignment to attrs.

The output from the script:

  Class: java.util.LinkedHashMap
Size: 2
Attributes: [file:/home/prystasj/file.txt, type:txt]
File: /home/prystasj/file.txt
Type: txt