i have a file, which i want to rename, from my current directory to a backupdirectory. My perl code is below
all my variables are defined. but the rename failed. the file permission my file is "-rw-rw-r--". could this be a problem?
I tried to use the mv command from the shell enviromnent, it works. could anyone advise the cause?
Sounds like you are trying to move a file between filesystems.
As Perl's rename is tied to the rename(2) system call, please check out the manpage for your system to check if cross-device move is not allowed. If so, then you may need to copy the file to the destination, and then remove the original one.
Don't overlook the footnote at the rename() function from the Perl documentation:
Quote:
Behavior of this function varies wildly depending on your system implementation. For example, it will usually not work across file system boundaries, even though the system mv command sometimes compensates for this. Other restrictions include whether it works on directories, open files, or pre-existing files. Check perlport and either the rename(2) manpage or equivalent system documentation for details.
i tried to use the following, and it was successful. Thank you.
As advised by you, i should include a mechanism to capture any trap, how can i do it? Is it
i read somewhere that if a system command fails, it sets a high bit, so to test for failure, the above way is suggested.
I realise even if i do not include the mechanism, and it fails, the error message will be printed, so i still need to explicitly include the mechanism?
I believe its more of a program design issue, would appreciate your advise.
As advised by you, i should include a mechanism to capture any trap, how can i do it? Is it
i read somewhere that if a system command fails, it sets a high bit, so to test for failure, the above way is suggested.
I realise even if i do not include the mechanism, and it fails, the error message will be printed, so i still need to explicitly include the mechanism?
I believe its more of a program design issue, would appreciate your advise.
For system calls, such as rename() as you used, check $! for error number (or string, depending on how you use) as in my earlier post. Please read
I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open())
I would like to run another PERL-script from first one, not... (1 Reply)
Hello All,
I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir.
rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed.
Can some body help me to... (2 Replies)
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)
Hi,
Can someone help me with a perl file to rename some files please? I can do it with regular command line using the below code, but I need to include this in another script and the other script is perl. I know nothing of perl.
for file in C*
do
newfilename=`echo $file | cut -c8-21-`... (8 Replies)
What I want seems to me should be simple but so am I so....
I have a Unix server that is running a program we will say logged in as UserA. The program is outputting a bunch of stuff to the terminal.
I would like to log in from my machine to the server as Either UserA, UserB or if needed... (2 Replies)
Hi,
While I am trying SFTP my machine to another unix machine ,
it was working fine till 10 min back.
But now i am getting the below error
"Request for subsystem 'sftp' failed on channel 0"
Could you please someone help me to solve or analyise the root cause...
Cheers:b:,
Mahiban (0 Replies)
Dear expert,
I have one server,in /var/adm/messages everyday present these messages:
Jan 3 06:01:30 SERVERGINTING genunix: WARNING: Device /pci@1d,700000/pci@1/scsi@2,1/sd@5,0 failed to power up.
Jan 3 06:01:31 SERVERGINTING scsi: WARNING: /pci@1d,700000/pci@1/scsi@2,1/sd@5,0 (sd45):... (2 Replies)
#!/usr/bin/perl -w
use POSIX qw(strftime);
$PID = strftime "%Y%m%d%H%M%S", localtime;
$filename = "original.list";
rename($filename,$filename.$PID)|| print "rename failed\n";
print $filename;The above code has no syntax error. But the renaming does not work. Anybody got a clue? (1 Reply)