I have to move files (one by one) from one dir to another, in such a way that the oldest file should be moved first followed by the latest file. The source dir (from where I am moving files) may contains a minimum of 20K files at any point of time. I am not able to use "ls -ltr" as it throws error - Arg list is too long.
Kindly help me in solving this.
The platform is UNIX Solaris. I will be keep on receiving files from another server to the source dir. I want to move files one by one to the destination dir becoz, there is a daemon application which will be always pooling this destination dir for any files and if a file is found, it starts processing it. This application is taking more time to start when the no: of files in its pooling dir (destin dir) is more. So, in my script I check if the no: of files in the destin dir is < 50 and if so, I have to start moving files (the file with oldest timestamp first, and so on, and file with latest timestamp at last).
At present, I use the following code:
But this is failing with the error- Arg list too long @ for i in `ls -t $sourceDir`. Please suggest me ways to handle this.
And the delta between the oldest and newest file may be 2 or 3 days, as in worst case we may be having many backlog files in the sourceDir when the daemon application is kept down for maintenance.
---------- Post updated at 07:38 PM ---------- Previous update was at 07:35 PM ----------
small mistake in the code....
mv $sourceDir/$i $DestinDir
Last edited by vbe; 10-15-2010 at 12:01 PM..
Reason: code tags please
I'd love to know where this "for i in open-ended-list" construct comes from.
Anyway, we can turn the script from a "for" loop to a "while" loop.
I'd suggest inserting some "sleep" statements in this script because it will loop at a ridiculous rate.
As an idea, try getting out of the inner loop with a "break" command when the destination directory has reached the limit. If you don't there is a good chance that you will process your files list out of order.
There is no code to deal with embryonic files. I hope that they arrive in $sourceDir under a name other than *.txt, then get renamed?
Hi All,
I got access in UNIX box from our client.
I am able to create folder, files, script etc.. in that folder.
here is the issue:
my login/base folder is = /home/ace
I have created 2 folders within it
Script
ScriptLog
in Script folder i have created 2 .ksh file
... (1 Reply)
I ve a client : <clientname> and a server: <servername>
Both of them running: HPUX B.11.31
SERVER outputs:
I ve shared a folder in <servername> called /test and the O/P for
# exportfs
- /test root=<clientname>,rw=<clientname>,ro ""
# showmount -e
export list for... (6 Replies)
I am very new to unix as well as shell scripting.
I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file
Please help me in this regard and many thanks in advance. (3 Replies)
Hi Friends,
I have installed a FTP Server on my Linux machine (Fedora 11).
I want the ftp users to be restricted to their own home dir using sftp.
But the said condition is met when the user logs in using ftp over port 21 and when the user logs in using sftp i.e. protocol 22, he/she has... (4 Replies)
Hi all,
if I have a dir with a mixture of files and directories in it and one of the directories *only* has read permission for the owner and I am not the owner - will I see it with an 'ls -la'.
I do not have access to a unix box at present to try this out.
Any thoughts gratefully received (1 Reply)
Hi!
i'm using FreeBSD 6.2 and hosting my pc to frens
in particular of sensitive information being saved to the PC, i would like to know is it possible for me to restrict user access to their /home dir. only?
and also, i wanted to restrict them listing files under /etc
thanks all! (10 Replies)
I am writing code to copy file if user dir exists.
Code snippet :
#!/bin/sh
if
then
cp ~user1/file file
else
cp ~user2/file file
fi
This code works if shell is ksh but not if shell is sh.
Can anyone suggest how this can work in sh script?
Thanks,
Ashish (1 Reply)
Hi Guys,
Im trying to set up FTP to my Apache Tomcat dir on my server so my web designer can FTP in and look at things in a live environment.
However at first I couldn't write to the dir, so i change some permissions, and now I cant access it at all!
Here is my LS -all output:
... (4 Replies)
How do I give specific user the ablity to create, delete, rename, and alter in a specific directory. I am using redhad 7.2 and would like to give a specific user the rights to a dirc in the main www directory. (1 Reply)