Error sending Unix command from Batch file over plink (asterisk issue)

Posted on 2013-08-30
Medium Priority
Last Modified: 2013-08-30
Im having trouble sendin the next command over plink from a batch file, its an asterisk issue.

I can execute it directly with putty or winscp command mode obtaining the result i need, however since i need to handle the output filename i need to call it from a batch file and im getting an error.

This is the command i have on the batch file (it returns the file name i need) that should write the filename in a given txt file (filename_here.txt)

plink -P 22 -l username -pw password machine.extension "ls -alrt C*.TXT | tail -1 | awk '{print $NF}'" >> filename_here.txt 2>&1

The output should be


however this is whats written in my txt file:

C*.TXT: No such file or directory
Question by:celtician
  • 2
LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 39453009
"plink" puts you into the home directory of the user "username" at the target server.

 Are you sure that a matching file exists in that directory? Please remember that "ls -alrt" does not recurse into subdirectories.

Better "cd" to the directory where you're hoping to find the file first, like:

plink  -l username -pw password machine.extension "cd /my/path; ls -alrt C*.TXT | tail -1 | awk '{print $NF}'" >> filename_here.txt 2>&1

Please note that I omitted "-P 22" because it's redundant. "22" is the default.

Author Comment

ID: 39453031
If i dont type in -p 22 the connection is not working, i dont know why, but i just know that by inputing 22 it works :)

I tried your suggestion and now its working, it wasn't looking in the directry i wanted.

Strange, do you know why is not entering directly that directory? just as a follow up, since your answer is correct :)

thank you!
LVL 68

Expert Comment

ID: 39453042
plink does not enter the directory in question because it's not the "home" directory of "username".

Thx for the points!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question