Rename Files in remote directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename Files in remote directory
# 1  
Old 07-02-2014
Question Rename Files in remote directory

Hi All,

I am creating a script which will connect to remote server with ssh and perfom below.
- Search in a directory
- Search for a pattern
- Check the size if greater than the size_limit rename the file.

Below is the code i have written.

Code:
ssh user@host <<EOF

find /tmp -name "abc*log" -type f -size +100c | awk '{print "mv " $0 " "$0"_BKUP" }' |sh

EOF

But it is not able to rename.

Below is the error encountered

Code:
mv: cannot stat `/tmp/abc1.log': No such file or directory

Kindly help me in identifying the issue.

Last edited by Scrutinizer; 07-02-2014 at 07:18 AM.. Reason: code tags
# 2  
Old 07-02-2014
Please use code tags as required by forum rules!

Show evidence that file abc1.log exists in /tmp on the remote node.
# 3  
Old 07-02-2014
Below are the list of files i am searching for. I have used abc*log as example
Code:
ls -rlt /export/SideSupport/logs/logs_backup/W_DDAServer*
-rw-r--r--   1 sideapp  sidegrp      870 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062914-011602
-rw-r--r--   1 sideapp  sidegrp       81 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062714-220103
-rw-r--r--   1 sideapp  sidegrp       81 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062714-220005
-rw-r--r--   1 sideapp  sidegrp      870 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062214-011602
-rw-r--r--   1 sideapp  sidegrp       81 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062014-220103
-rw-r--r--   1 sideapp  sidegrp       81 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.062014-220002
-rw-r--r--   1 sideapp  sidegrp      870 Jun 30 04:32 /export/SideSupport/logs/logs_backup/W_DDAServer.061514-011602


Last edited by Franklin52; 07-02-2014 at 11:07 AM.. Reason: Please use code tags
# 4  
Old 07-02-2014
You have been asked before to use CODE tags. It's not hard to do and it makes code/data far easier to read. Highlight the text and press the CODE icon, or manually wrap the text in [CODE] & [/CODE]

Anyway, I'm assuming that this is a listing from the remote server you are connecting to with ssh. Could you try:-
Code:
find /tmp -name "abc*log" -type f -size +100c|while read file
do
   printf "mv $file ${file}_BKUP\n"
   mv $file ${file}_BKUP
done

Does that help at all? The printf just produces some trace output. You can remove it if you are happy it works.



Robin

Last edited by rbatte1; 07-02-2014 at 09:33 AM.. Reason: Emboldening
# 5  
Old 07-02-2014
no i can see the same error
# 6  
Old 07-02-2014
Please post up the shortest script you have that reproduces this in [CODE]&[/CODE] tags along with the output.

It would be useful if the script had some tracing in it to show what it is actually trying to do so we don't theorise and miss something.


Thanks,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename (move) multiple files on remote server using sftp

I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help? #!/bin/ksh sftp -dev3 << ABC cd my_dir $(for i in TXT; do echo "ls *.$i" ; rename $x /new_dir/$x;... (1 Reply)
Discussion started by: Soham
1 Replies

2. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

3. UNIX for Dummies Questions & Answers

Rename files in a directory and move them

I have a directory e2e_ms_xfer/cent01 this contains the multiple files some of which will be named below with unique date time stamps e2e_ms_edd_nom_CCYYMMDD_HHMM.csv What I want to do is in a loop 1) Get the oldest file 2) Rename 3) Move it up one level from e2e_ms_xfer/cent01 to... (1 Reply)
Discussion started by: andymay
1 Replies

4. Shell Programming and Scripting

Copy down remote files and rename them to include the server name with full path

I need to pull down a good bit of files for another support team for an upgrade project. I have a server.list with all of the server names. I need to do two parts: FIRST: I have this example, but it does not list the server name in front of each line. #! /bin/bash for server in $(<... (10 Replies)
Discussion started by: asnatlas
10 Replies

5. Shell Programming and Scripting

How to Rename List of files in a directory

How can i rename list of files in a directory? (4 Replies)
Discussion started by: knip
4 Replies

6. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

7. UNIX for Dummies Questions & Answers

rename files based on their respective directory name

I have a number of files in directories labeled like this: /Data/tr_gray/tr_DTI/dti_FA.nii.gz (the brackets here represent a range of number that the files are labeled with) I need to rename each dti_FA.nii.gz file according to the name of the folder it resides in. For example, the file ... (3 Replies)
Discussion started by: tk0034
3 Replies

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

9. Shell Programming and Scripting

Rename many files in a directory

Hi, I have around 100 xml file in a directory. I need to rename the files from .xml to .xml1. So i tried using the following command: mv *.xml *.xml1 but i am getting the following error mv: when moving multiple files, last argument must be a directory Try `mv --help' for more... (8 Replies)
Discussion started by: ananthi_ku
8 Replies

10. Shell Programming and Scripting

rename files in remote server via ftp

Hi All, I want to rename set of files in the remote server which iam unable to do . i can rename only one file at a time . for example ftp $REMOTESERVER { rename $NAME1 $NAME2 } is working whereas ftp $REMOTESERVER { rename $NAME1*.dat $NAME2*.data } is not working ...... (4 Replies)
Discussion started by: dineshr85
4 Replies
Login or Register to Ask a Question