- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script Help - Coping and Moving Files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:27 AM
04-24-2002 07:27 AM
I have a technical question concerning a script. I want to copy and move files from one directory to another, but not if the files are being uploaded at the time. That would be a bad thing.
So, I need to add a piece that can read the file size, wait for 3-5 seconds,
read the file size again and then loop if they're not the same, which will wait another 3-5 seconds. Once the files are the same size, Then continue with the script.
Attached is a copy of my 1 page script.
Thank you for your help,
Laurie
lauriek@mail.park.edu
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:37 AM
04-24-2002 07:37 AM
SolutionYou need to put a test condition in the script
which goes like this :
while true
do
export SIZE=`ls -l filename | awk '{print $7}'`
if [ $SIZE = < expected size > ]
then
(command to be run)
exit
fi
sleep 90
done
where file name is the name of the file which is expected to reach the
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:39 AM
04-24-2002 07:39 AM
Re: Script Help - Coping and Moving Files
Let me give you a somewhat better way to do this. Call my fileage.pl script. It will silently report if a file has been modified within a given period of time. It exits with a 0 status if not and a status of 1 if the file has been modified. This is better than looking at file sizes. I would also look at a bit longer time period than 3-5 seconds.
In your script, do something like this:
SECONDS=30
fileage.pl -m -s ${SECONDS} ${YOURFILE}
STAT=$?
if [ ${STAT} -eq 0 ]
then
echo "File ${YOURFILE} not been modified in"
echo "${SECONDS}. It is safe to transfer."
fi
You can execute fileage.pl -u for full usage.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:42 AM
04-24-2002 07:42 AM
Re: Script Help - Coping and Moving Files
for FILE in `ls dir`
do
SIZE1=`ll $FILE | awk '{print $7}'`
sleep 5
SIZE2=`ll $FILE | awk '{print $7}'`
if [ $SIZE2 -eq $SIZE1 ]
then
execute command
else
don't execute
fi
done
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:44 AM
04-24-2002 07:44 AM
Re: Script Help - Coping and Moving Files
#!/opt/perl/bin/perl -w
# copycheck sourcedir destdir
use strict;
my ($sourcedir, $destdir) = @ARGV;
use File::Find;
use File::Copy;
find (sub {
$^T = time; # Now is now
-M < 0.02 and return;# File too new
copy $_, $destdir/$_";
}, $sourcedir);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:50 AM
04-24-2002 07:50 AM
Re: Script Help - Coping and Moving Files
#!/opt/perl/bin/perl -w
# copycheck sourcedir destdir
use strict;
my ($sourcedir, $destdir) = @ARGV;
use File::Find;
use File::Copy;
find (sub {
$^T = time; # Now is now
-M $_ < 0.02 and return;# File too new
copy $_, $destdir/$_;
}, $sourcedir);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 07:58 AM
04-24-2002 07:58 AM
Re: Script Help - Coping and Moving Files
Look at this sample script:
OPEN=`fuser ${YOUR_FILE} 2>/dev/null`
while [ "$OPEN" != "" ]
do
sleep 1
OPEN=`fuser ${YOUR_FILE} 2>/dev/null`
done
Hope this helps
Ruediger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 08:02 AM
04-24-2002 08:02 AM
Re: Script Help - Coping and Moving Files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2002 10:17 PM
04-24-2002 10:17 PM
Re: Script Help - Coping and Moving Files
thanks for your reply.
I know that only root can get access to the kernel and can run command fuser.
But I found in Lauries script the chown command. Therefore I thought the script will be started from root.
Ruediger
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 08:23 AM
04-25-2002 08:23 AM
Re: Script Help - Coping and Moving Files
are you certain that you do NOT want any checks wether the file to be copied/moved does not already EXIST in the target directory (deleting the existing one!)???
Just my $0.02,
Wodisch