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

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

"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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
celticianAuthor Commented:
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!
plink does not enter the directory in question because it's not the "home" directory of "username".

Thx for the points!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.