Sponsored Content
Top Forums Shell Programming and Scripting Problem renaming files on Solaris 10 server Post 302972263 by BRH on Tuesday 3rd of May 2016 12:46:01 PM
Old 05-03-2016
Problem renaming files on Solaris 10 server

Good day all.

I'm trying to rename some files in my home directory with some bizarre results. Basically I need to change the IP address in the filename to the hostname which I ggrep from within the file:

Code:
 
-rw-r--r--   1 bh694n   nrc         5095 May  2 20:03 alarms_999.189.161.146.log
-rw-r--r--   1 bh694n   nrc         4450 May  2 20:03 alarms_999.189.161.5.log
-rw-r--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_999.189.175.143.log
-rw-r--r--   1 bh694n   nrc         4450 May  2 20:03 alarms_999.189.175.20.log
-rw-r--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_999.190.152.231.log
-rw-r--r--   1 bh694n   nrc         4400 May  2 20:03 alarms_999.190.152.76.log
-rw-r--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_999.190.161.232.log
-rw-r--r--   1 bh694n   nrc         5227 May  2 20:03 alarms_999.191.152.220.log
-rw-r--r--   1 bh694n   nrc         4429 May  2 20:03 alarms_999.191.152.77.log
-rw-r--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_999.191.184.231.log
-rw-r--r--   1 bh694n   nrc         4419 May  2 20:03 alarms_999.191.184.52.log
-rw-r--r--   1 bh694n   nrc         5512 May  2 20:03 alarms_999.192.104.46.log
-rw-r--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_999.192.106.46.log
-rw-r--r--   1 bh694n   nrc         5508 May  2 20:03 alarms_999.193.171.214.log
-rw-r--r--   1 bh694n   nrc         5453 May  2 20:03 alarms_999.193.171.53.log
-rw-r--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_999.193.177.220.log
-rw-r--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_999.193.177.52.log

The command string I used:
Code:
for i in `ls alarm*.log`;do HOST=`/usr/sfw/bin/ggrep -A 1 sysidconf $i|tail -1`;mv $i alarms_${HOST}.log;done

What I get is this:
Code:
bh694n$ ls -ltr        
total 180
.logr--r--   1 bh694n   nrc         5095 May  2 20:03 alarms_wa1dc02scg
.logr--r--   1 bh694n   nrc         4450 May  2 20:03 alarms_wa1dc01scg
.logr--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_wy1pa02scg
.logr--r--   1 bh694n   nrc         4450 May  2 20:03 alarms_wy1pa01scg
.logr--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_al1ga02scg
.logr--r--   1 bh694n   nrc         4400 May  2 20:03 alarms_al1ga01scg
.logr--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_na1tn02scg
.logr--r--   1 bh694n   nrc         5227 May  2 20:03 alarms_ka1mo02scg
.logr--r--   1 bh694n   nrc         4429 May  2 20:03 alarms_ka1mo01scg
.logr--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_sn1tx02scg
.logr--r--   1 bh694n   nrc         4419 May  2 20:03 alarms_sn1tx01scg
.logr--r--   1 bh694n   nrc         5512 May  2 20:03 alarms_cl1oh02scg
.logr--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_ch1il02scg
.logr--r--   1 bh694n   nrc         5508 May  2 20:03 alarms_so1ca02scg
.logr--r--   1 bh694n   nrc         5453 May  2 20:03 alarms_so1ca01scg
.logr--r--   1 bh694n   nrc         4398 May  2 20:03 alarms_oa1ca02scg
.logr--r--   1 bh694n   nrc         4397 May  2 20:03 alarms_oa1ca01scg

Smilie

Where did I err?

Regards,
Bjoern
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Utility or script for renaming files on UNIX web server

Greetings! Does anyone know of a utility or a script for renaming files on a UNIX web server? I've seen several of these types of renaming utilities for Windows, but none for UNIX. I have 10,000 files that I need to rename in a several tier (deep) web site directory. I have the original... (1 Reply)
Discussion started by: everettr
1 Replies

2. Shell Programming and Scripting

Utility or script for renaming files on UNIX web server

Greetings! Does anyone know of a utility or a script for renaming files on a UNIX web server? I've seen several of these types of renaming utilities for Windows, but none for UNIX. I have 10,000 files that I need to rename in a several tier (deep) web site directory. I have the original... (2 Replies)
Discussion started by: everettr
2 Replies

3. UNIX for Advanced & Expert Users

problem with renaming files

Hi, I need to rename all the .txt files present in current directory to .dat files respectively in UNIX. for example: $ ls aaa.txt bbb.txt ccc.txt I need to change them to $ ls aaa.dat bbb.dat ccc.dat Is there any UNIX command to do this in one go? ... (3 Replies)
Discussion started by: Johny001
3 Replies

4. Shell Programming and Scripting

Loop renaming files w/ a count problem

:wall: Hello there, basically in my program where im stuck at is when it comes to rename the files in a loop. - the program counts the number of files w a given name (works!) - and then if the number of files is greater or equal to the MAX_VERSIONS (numbers of files allowed w the... (1 Reply)
Discussion started by: thurft
1 Replies

5. Shell Programming and Scripting

Help with renaming files in remote server

I have to write a script to get some files from remote server using FTP and rename it after the FTP. I use wildcard to get the file as i do not no the exact file name or the number of files in the remote server. My script is similar to the following... #!/bin/sh LOG=/Log/ftp.log ftp (FTP... (0 Replies)
Discussion started by: infossiva
0 Replies

6. Shell Programming and Scripting

Problem renaming files using variables

Hi, I have the following problem: I have a list of files: 1.txt 2.txt 3.txt 4.txt Then I have a list of variable names inside variable.txt: A B C D I'd like to rename 1.txt, 2.txt etc using the variables from variable.txt (2 Replies)
Discussion started by: hubleo
2 Replies

7. UNIX for Advanced & Expert Users

Problem with renaming files

I have about 1000 files containing the character * in the name. I need to find these files and replace the * with a -. I am working with HP UX v11. I am using the following command find . -type f -name '*\**' -exec bash -c 'f="$1"; mv "$f" "${f//\*/-}"' - '{}' \ People tell me it works for... (4 Replies)
Discussion started by: MikeDavid
4 Replies

8. Shell Programming and Scripting

Renaming Multiple Files in FTP Server

Hi Friends, I have a requirement to get multiple files from ftp(remote) server and once the files is copied to local machine , I need to move the files on to a different directory in ftp machine. FTP Machine : 9.9.999.999 Source File Directory : /ftpuser File Pattern: TMS* Now I have... (1 Reply)
Discussion started by: lokeshbao87
1 Replies

9. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

10. Solaris

X-server problem on Solaris 10

Hi, On my Sun Ultra 45, display was flickering. After changing PCI slot of graphic card (XVR-300), display stablized, but, now X-server not starting. I am getting following messages The X-server can not be started on display : 0... See file/var/dt/Xerrors for details. the output of... (8 Replies)
Discussion started by: rakhsin
8 Replies
RENAME(2)						      BSD System Calls Manual							 RENAME(2)

NAME
rename -- change the name of a file SYNOPSIS
#include <stdio.h> int rename(const char *old, const char *new); DESCRIPTION
The rename() system call causes the link named old to be renamed as new. If new exists, it is first removed. Both old and new must be of the same type (that is, both must be either directories or non-directories) and must reside on the same file system. The rename() system call guarantees that an instance of new will always exist, even if the system should crash in the middle of the opera- tion. If the final component of old is a symbolic link, the symbolic link is renamed, not the file or directory to which it points. CAVEATS
The system can deadlock if a loop is present in the file system graph. This loop takes the form of an entry in directory 'a', say 'a/foo', being a hard link to directory 'b', and an entry in directory 'b', say 'b/bar', being a hard link to directory 'a'. When such a loop exists and two separate processes attempt to perform 'rename a/foo b/bar' and 'rename b/bar a/foo', respectively, the system may deadlock attempting to lock both directories for modification. Whether or not hard links to directories are supported is specific to the underlying filesystem implementation. It is recommended that any hard links to directories in an underlying filesystem should be replaced by symbolic links by the system adminis- trator to avoid the possibility of deadlocks. Moving or renaming a file or directory into a directory with inheritable ACLs does not result in ACLs being set on the file or directory. Use acl(3) in conjunction with rename() to set ACLs on the file or directory. RETURN VALUES
A 0 value is returned if the operation succeeds, otherwise rename() returns -1 and the global variable errno indicates the reason for the failure. ERRORS
The rename() system call will fail and neither of the argument files will be affected if: [EACCES] A component of either path prefix denies search permission. [EACCES] The requested operation requires writing in a directory (e.g., new, new/.., or old/..) whose modes disallow this. [EDQUOT] The directory in which the entry for the new name is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted. [EFAULT] Path points outside the process's allocated address space. [EINVAL] Old is a parent directory of new, or an attempt is made to rename '.' or '..'. [EIO] An I/O error occurs while making or updating a directory entry. [EISDIR] new is a directory, but old is not a directory. [ELOOP] Too many symbolic links are encountered in translating either pathname. This is taken to be indicative of a looping sym- bolic link. [ENAMETOOLONG] A component of a pathname exceeds {NAME_MAX} characters, or an entire path name exceeds {PATH_MAX} characters. [ENOENT] A component of the old path does not exist, or a path prefix of new does not exist. [ENOSPC] The directory in which the entry for the new name is being placed cannot be extended because there is no space left on the file system containing the directory. [ENOTDIR] A component of either path prefix is not a directory. [ENOTDIR] old is a directory, but new is not a directory. [ENOTEMPTY] New is a directory and is not empty. [EPERM] The directory containing old is marked sticky, and neither the containing directory nor old are owned by the effective user ID. [EPERM] The new file exists, the directory containing new is marked sticky, and neither the containing directory nor new are owned by the effective user ID. [EROFS] The requested link requires writing in a directory on a read-only file system. [EXDEV] The link named by new and the file named by old are on different logical devices (file systems). Note that this error code will not be returned if the implementation permits cross-device links. CONFORMANCE
The restriction on renaming a directory whose permissions disallow writing is based on the fact that UFS directories contain a ".." entry. If renaming a directory would move it to another parent directory, this entry needs to be changed. This restriction has been generalized to disallow renaming of any write-disabled directory, even when this would not require a change to the ".." entry. For consistency, HFS+ directories emulate this behavior. SEE ALSO
open(2), symlink(7) STANDARDS
The rename() function conforms to IEEE Std 1003.1-1988 (``POSIX.1''). 4.2 Berkeley Distribution September 18, 2008 4.2 Berkeley Distribution
All times are GMT -4. The time now is 03:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy