sleep command after mv command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sleep command after mv command
# 1  
Old 01-03-2011
sleep command after mv command

Hi, I had to see sleep command after mv command in most of the shell scripts in an application. As I understand, script control moves to next statement only after the previous command is complete so, what is the use of having sleep command after the mv command in the scripts? A script is supposed to move around 1000 files in a day, based on the program it uses 10 seconds to sleep for every move. Thus, it spends around 3 hours in a day to do nothing and cause delay. Can I remove sleep command to have the script to run more quicker to minimize the processing time? Please suggest. Thanks!
# 2  
Old 01-03-2011
Check whether the "mv" actually moves the files. A "mv" within the same filesystem will just rename the inode and has little impact even for 1000 files.

If the files are moved to a different filesystem then there may be a reason to have a delay between "mv" statements to reduce the impact on overall system performance. This depends on the size of the files, the ambient load on the system and the type of filesystem involved. If for example these are mirrored filesystems and the files are large, the impact of moving 1000 files back-to-back could be high. With mirrored filesystems and large files the disc activity will continue long after the "mv" command has returned to the command line.

Check wheter the "mv" actually moves the files.
# 3  
Old 01-03-2011
Can you provide some sample code? Also, can you tell us if you are moving the files in the same or different filesystem, for as methyl points out this will change how mv performs its actions; and if either (or both) filesystem is local or remote to the system you are running your script on.
# 4  
Old 01-03-2011
Thanks for looking into it. Scripts moves files from one directory to the other directory in the same file system in a loop.
Code:
for file in `cat ${WK_DIR}/file_list`
do
    IND=`ls $file | cut -c10-10`
    if [[ $IND = [K-S] || $IND = W ]]
    then
       mv -f ${SOURCE_DIR}/$file ${TARGET_DIR}/$file
       sleep 10
    fi
done
exit

where WK_DIR, SOURCE_DIR and TARGET_DIR are the different directories under same file system.


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.
# 5  
Old 01-03-2011
Can't you just check for "$?" ?

'mv' (as well as almost every UNIX command or script) will return 0 if it succeeds, which should end up in the shell variable "$?".

You can also look into using the "||" operand to execute something if a command fails (e.g. is non-zero).

Code:
mv -f ${SOURCE_DIR}/$file ${TARGET_DIR}/$file || echo "Error moving file ${SOURCE_DIR}/$file ${TARGET_DIR}/$file"

I wonder what the application could be waiting for... Smilie

-dufftime
# 6  
Old 01-03-2011
Quote:
for file in `cat ${WK_DIR}/file_list`
do
IND=`ls $file | cut -c10-10`
if [[ $IND = [K-S] || $IND = W ]]
then
mv -f ${SOURCE_DIR}/$file ${TARGET_DIR}/$file
sleep 10
fi
done
exit

To be quite honest this script is dubious and would give syntax errors in my Shell.
Please give an example of filenames containing a significant character in character 10 and define the rule by which ones should be moved and which ones should not be moved.
Ps. The "sleep" is pointless if the Source and Target directories are definitely in the same filesystem.
# 7  
Old 01-03-2011
I have a couple of questions/comments:
Quote:
Originally Posted by lm_str
<snip>
Code:
for file in `cat ${WK_DIR}/file_list`

Just an observation, from bash:
The command substitution $(cat file) can be replaced by the equivalent but faster $(< file)
Quote:
Originally Posted by lm_str
Code:
do
    IND=`ls $file | cut -c10-10`
    if [[ $IND = [K-S] || $IND = W ]]

This can be combined into one comparison:
Code:
if [[ $IND = [K-SW] ]]

Quote:
Originally Posted by lm_str
Code:
       mv -f ${SOURCE_DIR}/$file ${TARGET_DIR}/$file
       sleep 10

I honestly can't figure out why you need the sleep.
What type of filesystem is being used?

Quote:
Originally Posted by lm_str
Code:
    fi
done
exit

<snip>

Last edited by m.d.ludwig; 01-03-2011 at 05:30 PM.. Reason: misread "ls" and "ls -l"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sleep command

I need help in script. I want my one script execute every time at 6:30 am and i have no cron access. So i am putting sleep command there , Script may took half an hour 35 min , it depend upon queries how much it take time, but that is not issue, So i want according to stop time of... (15 Replies)
Discussion started by: pallvi_mahajan
15 Replies

2. Shell Programming and Scripting

Help with sleep command:

Hi Frnz, I need to execute sleep command but i dont know the definite time. Let me put my req: I am running one shell script and this script creates some lock file in temp dir ...now in my script i want one function to go into sleep mode till this lock file exists..one lock file gone that... (6 Replies)
Discussion started by: gnnsprapa
6 Replies

3. Shell Programming and Scripting

Sleep Command

Hello, Need a little help with the script below. I can't get it to sleep :( I'm trying to get this to check if the process is running and if it is, wait 10 secs and check again. Keep doing this until it's not running and then stop checking and send the email. #!/bin/ksh mailto=`cat... (2 Replies)
Discussion started by: bbbngowc
2 Replies

4. Shell Programming and Scripting

Sleep command

Hi All, i am very new to shall script . i am not that much aware of sleep command , i want to terminate the sleep command after certain time. following is my code. while loop sleep 1800 messag=/status.sql donethe script will be on sleep untill the messag be comes P. here my requirement... (4 Replies)
Discussion started by: mandlysreedhar
4 Replies

5. UNIX for Dummies Questions & Answers

Help with sleep command

sleep 10 & Is this the write line of command to suspend 5 jobs for 10 minutes (6 Replies)
Discussion started by: senyor17
6 Replies

6. Shell Programming and Scripting

sleep command

Hi, Did the sleep command work for hours or only minutes just give description to work on my script waiting for the earliest response (5 Replies)
Discussion started by: thelakbe
5 Replies

7. UNIX for Dummies Questions & Answers

sleep command

Hi All I have a requiremnt to run a script inside another script. here i am pulling the record count from the table in oracle.If record count is greater than 0 the script is executed.The scripts updates the count in the table and again the count is found out and the condition is checked and same... (3 Replies)
Discussion started by: dr46014
3 Replies

8. Shell Programming and Scripting

Sleep Command

I am in need of some help; think I have confused myself. Here is the issue I am faced with. The script log file was fine, the nohup.out file has tens of thousands of lines like illegal use of sleep: sleep seconds So I assume there is something with the seconds calculation in the script... (1 Reply)
Discussion started by: Glove
1 Replies

9. UNIX for Dummies Questions & Answers

sleep command

If I give sleep(50) what does it mean? My program waits for further execution or all my other processes wait? (3 Replies)
Discussion started by: leewar
3 Replies

10. UNIX for Dummies Questions & Answers

How can I get a command to sleep < 1 second?

I am running a number of processes through a kill -15 loop as a temporary fix to some viscious memory leaks. I cannot pass the entire list of processes through the kill at once, because the nature of the monitoring my client has will cause the software to failover. Because of the large number of... (1 Reply)
Discussion started by: mattd
1 Replies
Login or Register to Ask a Question