Error while renaming the file in SFTP Session


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Error while renaming the file in SFTP Session
# 1  
Old 08-12-2015
Error while renaming the file in SFTP Session

Hi All

Below is the script I am trying to execute to rename a file in an SFTP session.

It is in GNU/Linux.

This script is for generic use and so I am passing arguments. Everything in the script works fine except "reading the filename in SFTP session"

In the below script the $Remote_server_source_path is read properly. The filename is read from the while loop. When i echo the filename, it is read correctly, but somehow it is not read in sftp session

Please help!!

Code:
#!/bin/sh
#set -v
file_path=$1
Remote_server_source_path=$2
Dest_path=$3
File_pattern=$4
LOGIN=$5
echo "File path at Laclede End :"$file_path
echo "Path FROM where the file has to be moved :" $Remote_server_source_path
echo "Path TO where the file has to be moved :" $Dest_path
echo "SFTP server Login : " $LOGIN
cd $file_path
echo $pwd
DIRNAME=$(echo `pwd` | rev | cut -d "/" -f1 | rev)
echo $DIRNAME
ls -ltr $File_pattern > tempfilelist
count=`cat tempfilelist | wc -l`
echo "Number of files found: " $count
cat tempfilelist | while read line
do
#echo $line
echo "Filename to be moved : "
filename= echo $line | awk '{print $9}'
echo $filename
sftp $LOGIN  << EOF
cd $Remote_server_source_path
pwd
rename "$Remote_server_source_path/$filename" "$Dest_path/$filename"
bye
EOF
done

---------- Post updated at 09:08 AM ---------- Previous update was at 09:07 AM ----------

I also tried removing the qoutes . It still doesnt work.
# 2  
Old 08-12-2015
This is wrong:

Code:
filename= echo $line | awk '{print $9}'

You already do this sort of thing correctly when you set DIRNAME, but you forgot to do so here. Also the extra space after the equals ruins it too.

Code:
filename=$(echo "$line" | awk '{ print $9 }' )

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-12-2015
ohh.. i see it!! I didnt realise that makes a difference, because it was printing the name right.

Thankyou so much!! It saved my day!. Smilie

---------- Post updated at 10:31 AM ---------- Previous update was at 10:30 AM ----------

And yes ofcourse, It worked!! Smilie. Thanks again Corona688!
This User Gave Thanks to sparks 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

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

2. Shell Programming and Scripting

mkdir -p option in SFTP session

Hi, I am trying to create more than one directory by using -p option in SFTP session. But it created a directory named -p and ended. It didn't throw any error. sxxxxxxx:(abc)/test> sftp abcuser@zxxxxxxx Connecting to zxxxxxxx... Password: sftp> pwd Remote working directory: /test... (3 Replies)
Discussion started by: gthangav
3 Replies

3. Solaris

sftp file renaming

Hi Admins, I am trying to get a file with different name including date format using sftp. For example --> get test.bak auto`date +"%Y%m%d"`err Here i am trying to get the file test.back with name auto20120126err But file is copied with the name auto`date --> date is not printing... (1 Reply)
Discussion started by: newaix
1 Replies

4. Shell Programming and Scripting

bulk renaming of files in sftp using script

Hi, Am using sftp (dsa method) to transfer 20 files from one server(sftp) to another (local). After the transfer is complete the files in the sftp server has to be renamed from .txt extension to .done extension ( aa.txt to aa.done, bb.txt to bb.done and likewise...). I tried rename command... (4 Replies)
Discussion started by: Sindhuap
4 Replies

5. Shell Programming and Scripting

Renaming a file while using SFTP

Hi All, I have a script which works perfectly for using SFTP commands. I use SFTP -b batchfile remoteuser@remoteserver. This batch file contains a command cd /dir1 put file1 I am wondering if there is a flag to rename a file on Remote server. I see the option rename file1... (6 Replies)
Discussion started by: Hangman2
6 Replies

6. Shell Programming and Scripting

Execute shell script within sftp session

Hi all , can any one tell me how to run a script within a sftp session. let me tell u in bit clear way : After I connected to sftp location , cd ing to some directory then I need to execute a one script. Please tell me if u have any idea on this . Looking forward to your reply guys... (1 Reply)
Discussion started by: sravan008
1 Replies

7. Solaris

Cygwin X Server error: xdmcp fatal error session failed session 23 failed for display

Hi, i got the following error when i tried to access the cygwin x server from a windows XP PC. "xdmcp fatal error session failed session 23 failed for display" Alternatively, when i tried to access the same Cygwin X Server from another windows XP PC which is on a different LAN... (3 Replies)
Discussion started by: HarishKumarM
3 Replies

8. Shell Programming and Scripting

Catch error from SFTP session

We have script running to SFTP some file to the remote server. The problem is the SFTP transfer returns an exit code of 0 even if there is permission error during file transfer, connection refuse (like when sftp server is down), thus, returning the status of the script as success. I was thinking... (3 Replies)
Discussion started by: The One
3 Replies

9. Shell Programming and Scripting

Error while renaming file

After running he following command to rename a file: # mv 'Linux CPU (EDF).sh' LinuxCpu(EDF).sh I am getting the following error: -bash: syntax error near unexpected token `(' Why is this happening? (2 Replies)
Discussion started by: proactiveaditya
2 Replies

10. UNIX for Advanced & Expert Users

sftp problem with user id of no telnet session allowed

We used to have a ftp user id with no telnet session allowed in server side. We used this ftp user id in script by transferring file from client to Server. Currently we need to implement sftp to replace ftp. We have tested few round and working fine by using sftp with normal user id (allow... (2 Replies)
Discussion started by: superdougl
2 Replies
Login or Register to Ask a Question