pwd
/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22
ls: cannot access /var/source/logging/target/d2/logging/target/fixed: No such file or directory
ls is working in local directory and not doing at remote server.
Kindly help how can i fix this.
Requirement is if connection work then ls the file into a current list and if connection failed then cp from old pulled file to current list
but ls is trying to run on local path after ssh so its unable to find the path.
My requirement is ssh connection established
if true then list files of /var/source/logging/target/d2/logging/target/fixed and copied to $dpi_42_fixed_currentFileList (local directory )
if connection failed
then
copy $dpi_42_fixed_pulledFileList $trnsnt_dpi42_fixed_currentList
I would strongly suggest running your script with tracing enabled. In other words, add the line:
set -xv
immediately after the first line of your script:
#!/bin/bash
Your inconsistent variable naming convention (sometimes using dpi_42 , sometimes using dpi42 ), the fact that you define some variables you never use, and the fact that you misspell "destination" with three "i"s instead of an "e" and two "i"s makes it likely that you might have used a variable that hasn't been defined when you intended to use a variable that had been defined with a similar, but slightly different, spelling.
One might also consider adding:
set -u
to cause your script to get an error whenever it tries to expand a variable that hasn't been set (instead of silently expanding to an empty string).
Thank you very much, but i need to test the connection and then
cat
else copied .
so how can i achieve that.
truncate --size 0 $dpi_42_fixed_currentFileList
i need to perform at every run its important as per the requirement.
------ Post updated at 05:29 PM ------
kindly guide RudiC
------ Post updated at 05:33 PM ------
Thanks @MadeInGermany you almost solved my concern, but i need to validate the connection.
if connection happen successfully then only ls or cat should run else copy the file from mentioned file to there.
kindly guide.
If you want to write to a local file from an SSH session, you would need to pass that to STDOUT within the SSH and then redirect the output of the whole SSH to a file on your local machine, something like this:-
If you have multiple statements to execute, you would need to do something more like this:-
ssh user@server "ls /path/to/files
date
uname -a" > /tmp/file_list
Given that you have this in a function, you could also remove any redirection form the function and then call it capturing all the output from the function call:-
Do any of these options help? If you really need a good chunk of remote processing to return some sort of filtered output and there may be other output you don't want, then you might have to write a file on the remote server and then copy it back to your local machine in a separate step to interrogate it. If you have SSH keys all in place, it shouldn't be too hard.
I hope that these help.
Let me know if I've completely missed the point.
Robin