Using ssh to transfer file not working inside if-condition

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using ssh to transfer file not working inside if-condition
# 1  
Old 11-03-2010
Using ssh to transfer file not working inside if-condition

Hi all,

ssh uname@remote_server 'cat /tmp/remote_file_name > home_dir/a512386/new/local_file_name'

The above given command is working fine.
but if i try to move the file only if exists in the remote server i.e) giving the same within if condition it executes but the file is not stored in my local.
cmd= ssh a512386@ "
if [ -f /tmp/remote_file_name ]
cat /tmp/remote_file_name > local_file_name

Thanks in advance

Last edited by Scott; 11-03-2010 at 09:37 AM.. Reason: Please use code tags
# 2  
Old 11-03-2010
This is because everything you do is remote. If you want to create/copy the file locally (you are not moving it btw.), then you can try something like this:
ssh a512386@ "if [ -f /tmp/remote_file_name ]; then cat /tmp/remote_file_name; fi" > local_file_name

#or without redirection stdout and scp instead

ssh a512386@ "if [ -f /tmp/remote_file_name ]; then scp /tmp/remote_file_name yourbox:/somedir; fi"

You could also just skip the test if the file exists and scp right away while redireting stdout and stderr to /dev/null, if that is ok for you.
scp a512386@ /somedir > /dev/null 2>&1

.. or to some logfile instead of course.

If I didn't get you wrong and meant with "local" your local box.

Last edited by zaxxon; 11-03-2010 at 09:52 AM.. Reason: added comment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

SSH SSH encountered 1 errors during the transfer

This issue was resolved due to using the correct user transferring the file over to the desktop. (1 Reply)
Discussion started by: Computergal2104
1 Replies

2. Shell Programming and Scripting

Replace text inside XML file based on condition

Hi All, I want to change the name as SEQ_13 ie., <Property Name="Name">SEQ_13</Property> when the Stage Type is PxSequentialFile ie., <Property Name="StageType">PxSequentialFile</Property> :wall: Input.XML <Main> <Record Identifier="V0S13" Type="CustomStage" Readonly="0">... (3 Replies)
Discussion started by: kmsekhar
3 Replies

3. Shell Programming and Scripting

Automating file transfer between two SSH enabled server.

Hi Experts, Few more words to the title, both the servers are ssh enabled but I have read only access to the second server, so I cannot automate SFTP process using RSA/DSA keys. I am using Control M to trigger the script and do not want any manual intervention to enter the password to complete... (4 Replies)
Discussion started by: nchourasiya
4 Replies

4. UNIX and Linux Applications

Central Location for all ssh Keys and Settings Unattended Secure File Transfer

I am developing an application that submits command line file transfers using ssh (Sun to Sun) and Tectia ssh (Sun to Windows Server) embedded in the code. Potentially many different trusted people will start the programs. Is there a way to have all the settings and keys localized so that there is... (0 Replies)
Discussion started by: PowersThatB
0 Replies

5. UNIX for Advanced & Expert Users

SSH : File transfer

We have tow servers.One Linux server (A) and one unix server (B). How can i set up so that files can be sftped from A to B. Please let me know the steps (4 Replies)
Discussion started by: dr46014
4 Replies

6. Shell Programming and Scripting

If condition inside while???

Hi source is text file named alpha.text containing entries ABC DEF XYZ YYY BBB I need a small shell script which should do read the entries in alpha.text one by one and check it with the current date. If the date is Mon (monday) and entry read from the file is 'DEF' then this should... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

7. Shell Programming and Scripting

condition inside a for loop

I have a for loop in my script as shown below. for file_path in $file_list ; do code .......... ...... done Can i restrict the number of files parsing to the variable file_path as 50? That is, even if I have some 100 files in file_list, I need to take only 50 files for... (7 Replies)
Discussion started by: Vijay06
7 Replies

8. AIX

How to use SSH Secure File Transfer tool from windows to AIX without password?

If I use SSh Secure File Transfer tool on Windows, I want to transfer file from windows to AIX without password, how to do it? (6 Replies)
Discussion started by: rainbow_bean
6 Replies

9. Shell Programming and Scripting

script to check for a condition inside a file

Hi I am writing a script file which sends the log files along with their size in a folder named log to a file called temp.log using the following cmd: ls -st 190_GSTV_HUX_003QISCGSK026** >> /home/user/temp.log the temp.log looks like this: 16 190_GSTV_HUX_003QISCGSK026_message070321.log ... (11 Replies)
Discussion started by: kiran1112
11 Replies

10. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies
Login or Register to Ask a Question

Featured Tech Videos