2

I may have done some copy/move operation involving large or many files. In bash I would like some hint that that operation is over. Is there anything I can do?

enter image description here

At first I thought, waiting on a pid should do the trick. Hence during one such operations, I ran top and found that mount.ntfs was taking most of the cpu. However, post this file operation (after the dialog automatically disappears) that process is still running.

Hence I ruled out that one. Any ideas on how I can know when my OS has dismissed that dialog?

deostroll
  • 1,769
  • See if the answers in https://askubuntu.com/questions/748860/how-can-i-use-the-eos-terminal-notification-in-ubuntu help. – DK Bose Jan 15 '18 at 12:30
  • Are you moving your files using mv or cp? Then the simple command sync will do the trick. As soon as sync returns, the file transfer is complete. – DamBedEi Jan 15 '18 at 12:44
  • if I had used mv or cp I'd get their PIDs. I have another script that waits on a pid...life would have been simple if that was the case... :) – deostroll Jan 15 '18 at 12:49
  • Please tell us what commands there are in your script. Otherwise we can only guess. You can edit your original question to show us the script as 'code'. – sudodus Jan 15 '18 at 13:06
  • 1
    That code is immaterial to this question. However, I am linking to it: here – deostroll Jan 15 '18 at 14:44
  • I see. I thought that your script contains the commands or GUI application programs that perform the file operations. So I have this new request: Please tell us what commands or GUI application programs you use to perform the file operations. Otherwise we can only guess. – sudodus Jan 15 '18 at 15:38
  • 1
    I use nautilus. I thought that ui was something that belonged to nautilus – deostroll Jan 15 '18 at 18:27
  • You can start a nautilus process with nautilus --no-desktop & pid=$! and check for its pid, but I think it will not really help, because nautilus does not stop when it has finished writing. And furthermore, the write process is probably buffered (and not really finished) anyway. I think using syncand iotop (as in my answer) will give you useful information, even if they do not answer your question exactly. – sudodus Jan 15 '18 at 18:56

5 Answers5

2
  • The first step is to check that the copy operation has finished. I think you have already checked for this step.

  • The second step is to check that the buffers are flushed (that buffered data in RAM is finally written to the target device, so that the file content is really stored in a file in a partition in the drive).

    You can run sync to flush the buffers. When sync is done and bash returns to prompt, this second step has also finished.


  • There is a tool to monitor the read/write activities, iotop. Install it with

    sudo apt install iotop
    

    and run it for example with the following command line

    sudo iotop -o
    
sudodus
  • 46,324
  • 5
  • 88
  • 152
0

Check source code for progress_bar in the below git repository:

https://github.com/Kiran-Bose/supreme

Also try custom bash script package supreme

Download the deb file from the above repository and install it on debian based systems.

Functionality overview

(1)Open Apps ----Firefox ----Calculator ----Settings

(2)Manage Files ----Search ----Navigate ----Quick access

            |----Select File(s)
            |----Inverse Selection
            |----Make directory
            |----Make file
                                          |----Open
                                          |----Copy
                                          |----Move
                                          |----Delete
                                          |----Rename
                                          |----Send to Device
                                          |----Properties

(3)Manage Phone ----Move/Copy from phone ----Move/Copy to phone ----Sync folders

(4)Manage USB ----Move/Copy from USB ----Move/Copy to USB

KIRAN B
  • 101
0

Without seeing the actual script it's difficult to know what kind of commands you are using for your file operations.


One very simple option could be to simply create a temporary file once your copy/move action is finished, like this

#copy action

cp $1 /home/user/backup/
touch /tmp/finished.tmp

and then check if the file is there or if there are recent changes with

ls -lha /tmp/finished

or for an automatic periodic check

watch ls -lha /tmp/finished

Depending on your needs you could name each temporary file like the copy/move job it represents, maybe all in the same directory

# set the variable JOBNAME via input or via sourcename
# JOBNAME=$SOURCE
# JOBNAME=$2
mkdir /tmp/copyjobs

# your copy job here

touch /tmp/copyjobs/finished.$JOBNAME.tmp

# your next copy job here 

touch /tmp/copyjobs/finished.$JOBNAME.tmp

Then watch the whole directory

watch ls -lha /tmp/copyjobs/

Depending on your skill you can also use loops and so on.


Tools like rsync have a built in progress bar for the commandline, so you can see how far along your job is with --progress or -P.

But rsync might not be the right tool for the job.

Robert Riedl
  • 4,351
0

"gcp" is your friend :)

Is this what you needed?

$ gcp -rf test.file tmp/
Copying 404.32 MiB 100% |############################| 471.12 MB/s Time: 0:00:00
0

Supposed you use cp, the process can start a second one

cp SOURCE TARGET 
ALERTCOMMAND

There is no predefined alert command, but you can issue whatever you have and seems appropriate, maybe play an audio snippet with an audio player to raise awareness. In former times, when people had optical drives, opening them with the eject command was an option, too. :)

cp SOURCE TARGET && FANFARE || REQUIEM 

Again, there is no such command like FANFARE or REQUIEM. Depending on success or failure you may issue different commands in the same line. Be creative. On the same virtual Desktop, a popping up new program raises awareness - see man zenity for example. Or use xmessage:

cp SOURCE TARGET && xmessage "Done"
user unknown
  • 6,507