Unable to ssh and list files in local directory from remote.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to ssh and list files in local directory from remote.
# 1  
Old 09-26-2018
Unable to ssh and list files in local directory from remote.

Code:
#!/bin/bash
script_work_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_work_area"
script_config_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_config"
dpi_sourceServerList=$script_config_dir"/dpi_sourceServerList"
dpi_srvr_42="rtm@1.1.1.1"
trnsnt_landingFilesDir="/DPICDR/sadiq_rtm/PORT22"
dpi_42_sourceFilesDir="/var/source/logging/target/d2/logging/target"
dpi42_landing_files=$trnsnt_landingFilesDir"/dpi42_landing_files"
dpi_42_fixed_currentFileList=$script_work_dir"/dpi_42_fixed_currentFileList"
dpi_42_fixed_toBePulledFileList=$script_work_dir"/dpi_42_fixed_toBePulledFileList"
dpi_42_fixed_pulledFileList=$script_work_dir"/dpi_42_fixed_pulledFileList"
logger=$script_work_dir/connection.out


get_dpi42_currentFiles()
{    
truncate --size 0 $dpi_42_fixed_currentFileList
##ssh $dpi_srvr_42 -p 22 ls $dpi_42_sourceFilesDir/fixed | grep '\.tgz$'" > $dpi_42_fixed_currentFileList 2>/dev/null
    ssh -o "BatchMode=yes" -p 22 $dpi_srvr_42 
    status=$?
    if [ $status ==0 ];
    then
    ls $dpi_42_sourceFilesDir/fixed | grep "\.tgz$" > $dpi_42_fixed_currentFileList 2>/dev/null;
    else
    echo "Connection refused $dpi_srvr_42" >> $logger
    cp  $dpi_42_fixed_pulledFileList $trnsnt_dpi42_fixed_currentList
    break;
    fi 
}

pulling_dpi42Files()
{
while true
do
    get_dpi42_currentFiles
done
}
pulling_dpi42Files

------ Post updated at 09:22 AM ------

Error :

Code:
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

------ Post updated at 09:53 AM ------

[CODE]

Last edited by sadique.manzar; 09-26-2018 at 07:37 PM..
# 2  
Old 09-26-2018
Code:
ls: cannot access /var/source/logging/target/d2/logging/target/fixed: No such file or directory

To make a wild guess, there's no such file or directory.

Can you login manually and confirm the existence of such a directory?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-26-2018
Yes directory is there.

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


Kindly guide how can i achieve that.
# 4  
Old 09-26-2018
I would strongly suggest running your script with tracing enabled. In other words, add the line:
Code:
set -xv

immediately after the first line of your script:
Code:
#!/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:
Code:
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).
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 09-26-2018
Code:
#!/bin/bash
script_work_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_work_area"
script_config_dir="/home/websys/TEST_dpi_42_file_trnsfer_engine/PORT22/script_config"
dpi_srvr_42="rtm@1.1.1.1"
trnsnt_landingFilesDir="/DPICDR/sadiq_rtm/PORT22"
dpi_42_sourceFilesDir="/var/source/logging/target/d2/logging/target"
dpi42_landing_files=$trnsnt_landingFilesDir"/dpi42_landing_files"
dpi_42_fixed_currentFileList=$script_work_dir"/dpi_42_fixed_currentFileList"
dpi_42_fixed_pulledFileList=$script_work_dir"/dpi_42_fixed_pulledFileList"
logger=$script_work_dir/connection.out

#-----------------------------------------------------------------------------------------------------
mkdir -p $script_work_dir

if [ ! -e $dpi_42_fixed_currentFileList ] ; then
    touch $dpi_42_fixed_currentFileList
fi

if [ ! -e $dpi_42_fixed_pulledFileList ] ; then
    touch $dpi_42_fixed_pulledFileList
fi
#--------------------------------------------------------------------------------------------------------
get_dpi42_currentFiles()
{    
    
    truncate --size 0 $dpi_42_fixed_currentFileList
  ##ssh $dpi_srvr_42 -p 22 "ls $dpi_42_sourceFilesDir/fixed" > $dpi_42_fixed_currentFileList 2>/dev/null
  ##ssh $dpi_srvr_42 -p 22 ls $dpi_42_sourceFilesDir/fixed | grep '\.tgz$'" > $dpi_42_fixed_currentFileList 2>/dev/null
    ssh -n -o "BatchMode=yes" -p 2233 $dpi_srvr_42 "echo 2>&1" 
    if [ $? -eq 0 ];
    then 
    ls $dpi_42_sourceFilesDir/fixed | grep '\.tgz$'  > $dpi_42_fixed_currentFileList 2>/dev/null;
    else
    echo "Connection refused $dpi_srvr_42" >> $logger
    cp  $dpi_42_fixed_pulledFileList $dpi_42_fixed_currentFileList
    break;
    fi 
}
get_dpi42_currentFiles

------ Post updated at 11:11 AM ------

I had not posted the full code, so kindly ignored the unused variables.
# 6  
Old 09-26-2018
Are you aware that your ssh login does an echo 2>&1 and immediately quits? The entire if ... fi branch is executed on the local node.
This User Gave Thanks to RudiC For This Post:
# 7  
Old 09-26-2018
In post#1 you had an attempt to run a remote command and redirect its output to a local file:
Code:
ssh -nqx $dpi_srvr_42 -p 22 "
  ls $dpi_42_sourceFilesDir/fixed | grep '\.tgz$'
" > $dpi_42_fixed_currentFileList

The following does the opposite, it runs a local command and redirect its output to a remote file:
Code:
ls $dpi_42_sourceFilesDir/fixed | grep '\.tgz$' | ssh -qx $dpi_srvr_42 "
  cat > $dpi_42_fixed_currentFileList
"

This one needs a command on the remote site, in this case cat that does nothing than copying from stdin to stdout. The stdin is what is piped to ssh.
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting SSH Output From Remote to Local Session?

Hi everyone, after about 2 days of scratching my head on this one, I'm finally ready to punt this and ask for some actual help. Here's the situation. We have 1 server, that runs multiple VM's. To gain access to those VM's we ssh from host01 to the other vm hosts. For example when we first log... (4 Replies)
Discussion started by: Lost in Cyberia
4 Replies

2. Shell Programming and Scripting

Using expect to remote SSH and write to a local file

Hi Guys, So what I am trying to do is : Host A should do a SSH to Host B to F. Login to the remote host and gather the output of uptime and write to to a file in HostA. So by the end of the script, HostA should contain a file that contains the uptime output of Host B,C,D,E,F. Right now... (1 Reply)
Discussion started by: Junaid Subhani
1 Replies

3. Solaris

Unable to list files in a directory

Hi have a system running solaris with a mount point running 58% capacity used, but unfortunately when I type ls -lrtin a specific directory, it returns: ls: Not enough space. I suspect there are millions of files in this directory. So what I did is to create a script like this: touch -mt... (13 Replies)
Discussion started by: fretagi
13 Replies

4. UNIX for Advanced & Expert Users

Unable to ssh to remote server

Hi, I have two SunOs sparc servers mac1 and mac2. I have exchanged keys between them inorder to passwordless login ssh from mac1 to mac2. However, it is failing after authentication. Part of the debug is as below. Please suggest whats wrong and how do i fix that!! Note: i do not have... (1 Reply)
Discussion started by: mohtashims
1 Replies

5. Shell Programming and Scripting

How to Compare local & remote Files over ssh?

I want to make a script to compare list of files in terms of its size on local & remote server whose names are same & this is required over ssh. How can I accomplish this. Any help would be appreciated. (1 Reply)
Discussion started by: m_raheelahmed
1 Replies

6. Shell Programming and Scripting

Replicate remote directory to local directory with ftp

I have system that generate files every 1 hours , i only have ftp connection from my local server to remote . $ ls -al -rw-r--r-- 1 water None 0 Feb 7 18:09 a.0800 -rw-r--r-- 1 water None 0 Feb 7 18:09 a.0900 -rw-r--r-- 1 water None 0 Feb 7 18:09 a.1000 is there any perl / php... (3 Replies)
Discussion started by: before4
3 Replies

7. Shell Programming and Scripting

ssh sending local variable to remote system

I am running a useradd script, which works locally but I want to take some of that local information and send it to a remote system, ssh keys are set up between the two systems. I am attaching the script, look at the section titled "Sending information to FTP2" Removed attachment, added... (0 Replies)
Discussion started by: slufoot80
0 Replies

8. UNIX for Dummies Questions & Answers

File listing from remote to local directory

Hello, I have a file at remote server. I have to select only current day's files that are dropped on ftp server. The files do not have date or timestamp on them. so I plan to get the file listing from remote server to the local server. Based on file listing date I can find out when the files... (2 Replies)
Discussion started by: pavan_test
2 Replies

9. Shell Programming and Scripting

FTP files from different directory from remote server to one directory in local

Hi All, I want to search for .log files from folders and sub folders in remote server and FTP them to one particular folder in the local machine. I dont want to copy the entire directory tree structure, just have to take all the .log files from all the folders by doing a recursive search from the... (3 Replies)
Discussion started by: dassv
3 Replies

10. Solaris

unable to ssh to remote host

server is ok, I can login on console. however, when I use SSH teachia, there is no repsond. i have check ps-ef | grep ssh, it shows ok. restart ssh too. still not working. Anything else I need to check? # ps -ef | grep ssh root 24706 1 0 Jun 12 ? 0:00... (7 Replies)
Discussion started by: uuontario
7 Replies
Login or Register to Ask a Question