LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-11-2018, 02:11 PM   #1
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Rep: Reputation: 1
Moving files with Zenity


Hi

I have to send files to a remote drive (15 miles away) every now and then.
I send them one at a time. Each one takes up to an hour.
So I wanted to automate it using Zenity.

The idea was to send one file, wait, say 30 minutes, and send the next till the directory was empty.

I could do it with:
Code:
find "$d1"/* -exec mv {} "$d2" \; -exec sleep "$result" \;
But I decided to get cocky and see if the progress bar would show a percentage of the 30 min for each file transferring.

It now throws everything across at once.

Code:
#!/bin/bash
cd ~/Downloads
d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
delay="$(zenity --entry --title="Bulk Move" --text="Enter delay in minutes:")"
result=`echo "$delay *60" | bc`
counter=1
pc=`echo "$result/100" | bc`
(
find "$d1"/* -exec mv {} "$d2" \;
while [ counter -le 100 ]
do
sleep "$pc"
((counter++))
echo "$counter" 
done) | zenity --progress --percentage=0 --auto-close
Anybody tell me where I've goofed?
I don't even know if I've succeeded with the progress bar (probably not).

Last edited by Fitch; 03-11-2018 at 02:14 PM.
 
Old 03-11-2018, 07:54 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
What exactly is the object here? You want a progress bar for the transfers? I can't get a grasp on what's going on. How are the two drives connected, Internet? You can get a progress bar with rsync, using pv or the --progress switch. I've never used zenity for file transfer applications.

Perhaps if you give more surrounding context about the situation. Do you just like gui dialogs? How is it you're able to use the mv command on a drive 15 miles away. Do you have a tunnel? I'm just missing a lot here.
 
Old 03-11-2018, 08:55 PM   #3
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Original Poster
Rep: Reputation: 1
If I put a file into the Synology Cloudstation directory, it is transferred by the Synology Sync app to the Synology NAS 15 miles away.
That's it.

So as far as Zenity is concerned, it is a simple case of transferring files, one at a time, from one directory in my computer to another directory in my computer.

At the moment, I test it just with directory fred and directory joe, with about 6 small text files, and a delay of 1 minute. That's how I know it doesn't work.

I just wanted to do it on its own, without me, and with some visual progress on how long it is till the next file transfer..

The original one (below) does, but it has no meaningful progress, just a bored Cylon.
Code:
#!/bin/bash
(
cd ~/Downloads
d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
delay="$(zenity --entry --title="Bulk Move" --text="Enter delay in minutes:")"
result=`echo "$delay *60" | bc`
find "$d1"/* -exec mv {} "$d2" \; -exec sleep "$result" \;

) | zenity --title="Timed Bulk Move in progress" --progress --pulsate --auto-close &

Last edited by Fitch; 03-11-2018 at 09:03 PM.
 
Old 03-12-2018, 07:07 AM   #4
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
wouldn't it be better to actually check when one transfer has finished, then start the next?
instead of guesstimating some delay?

and why is your NAS so slow?

also you don't need bc for integer arithmetics, and sleep can take e.g. "sleep 1m" = sleep one minute etc.
 
Old 03-12-2018, 08:27 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Fitch View Post
Hi

I have to send files to a remote drive (15 miles away) every now and then.
I send them one at a time. Each one takes up to an hour.
So I wanted to automate it using Zenity
...
now theres your problem, zenity isnt used for automation. its used for creating gui dialogs for the user to manually interact with.

does synology cloudstation provide any normal interfaces like ssh/scp, nfs ?

Last edited by schneidz; 03-12-2018 at 08:37 AM.
 
Old 03-12-2018, 09:46 AM   #6
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Original Poster
Rep: Reputation: 1
I send these files one at a time to a drive that has no high speed fibre.
The Synology sync can only handle one file at a time, as because there is no high speed line, the file takes about an hour to send. More than 1 file at a time, and Synology can't handle it.
I send at night. I just want to see the bar creep up, so I know it's working, leave it on and go to bed.
I do not own the drive.
The Linux Synology app is extremely basic, and I can give no details on it.

Is this not just a problem with syntax?
Going deep into the reason why isn't helping.
Perhaps you should let this post die, and I'll unsubscribe.

Last edited by Fitch; 03-12-2018 at 09:55 AM.
 
Old 03-12-2018, 11:04 AM   #7
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I see your dilemma. You'd like to use a GUI window to run the 'mv' command, and you want a progress bar to check progress of the file transfer. Zenity won't do that. It will show the progress of a number of tasks, but only how you tell it to. See this: https://ubuntuforums.org/showthread.php?t=2172828

If you use rsync --progress to transfer the files, it will actually tell you the progress of the transfer. I'm still a bit in the dark in that you say you can only transfer one file at a time. All file transfer programs do that. They don't transfer more than one file simultaneously.
 
Old 03-12-2018, 11:30 AM   #8
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
maybe you can hax something like this:
Code:
[schneidz@hyper stuff]$ scp burdenof80proof2.0.exe schneidz@localhost:stuff/s
schneidz@localhost's password: 
burdenof80proof2.0.exe                                          100%   41MB  21.3MB/s   00:01
 
Old 03-12-2018, 12:38 PM   #9
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Original Poster
Rep: Reputation: 1
Not really, I wanted the mv command to move files one at a time, and use the sleep command between each transfer, piped to Zenity.
Below was another method used.
I can do the move command one at a time,

In another attempt:

I used :
Code:
for i in {1..100..1}; do echo $i; sleep "$pc"; done | zenity --progress --percentage=0 --auto-close
with pc set to 1, and it works great alone.

And using a different idea, I fitted it into:

Code:
#!/usr/bin/env bash

cd ~/Downloads
d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
delay="$(zenity --entry --title="Bulk Move" --text="Enter delay in minutes:")"
seconds=`echo "$delay *60" | bc`
pc=`echo "$seconds/100"| bc`
## Find all files and folders in the current directory, sort
## them reverse alphabetically and iterate through them
find "$d1" -maxdepth 1 -type f | sort -r | while IFS= read -r file; do
    ## Set the counter back to 0 for each file
    counter=0;
    ## The counter will be 0 until the file is moved
    while [ $counter -eq 0 ]; do
          ## Move the current file to $target and increment
          ## the counter.
          mv -v "$file" "$d2" && counter=1;
			 for i in {1..100..1}; do echo $i; sleep "$pc"; done | zenity --progress --percentage=0 --auto-close
     done;
done
But the for next sleep command flashes through, and each file transfers every second.

Last edited by Fitch; 03-12-2018 at 12:39 PM.
 
Old 03-12-2018, 12:58 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
if it takes 1 hour to move 1 file why are you sleeping it for 30 minutes between each transfer? My brain wonders. When they will be moved in series one after the other. why are you waiting 30 minutes between each file? I'd think an hour each is long enough.

The math behind it would be start size of file, get rate of transfer, and do an approximate of time it takes until it reaches zero. then have it spit out the results every x seconds, or minutes to update you. or have it get total size at start, rate of transfer then update the stats of the amount transferred.

rate of transfer, amount transferred - total size = time it will finish. something like that, as far as looking at a bar in lue of numbers to tell you what is going on. that is out of my area of off the top of my head information.

how to calculate rate of transfer
https://www.wikihow.com/Calculate-Data-Transfer-Rate

I'd think if you're hooking up on a given static IP then use the network tools to get rate of transfer (ROT) to watch that IP / Port to get ROT, then do the math on each file max size - (M)bits transferred = time left.

Last edited by BW-userx; 03-12-2018 at 01:04 PM.
 
Old 03-12-2018, 01:06 PM   #11
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Original Poster
Rep: Reputation: 1
Again, you're trying to read too much into this.
If they are smaller files, I would set the delay around 30 minutes.
If they are larger ones, up to an hour.
During the daytime, the transfer rate is around 30k per second.
At night the rate is 400 - 500 Kb per second.
I have no control over this. British Telecom just haven't got around to that village yet with fibre.
 
Old 03-12-2018, 05:59 PM   #12
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 22.04
Posts: 29

Original Poster
Rep: Reputation: 1
Done.

Code:
#!/usr/bin/env bash
#
cd ~/Downloads
d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
delay="$(zenity --entry --title="Bulk Move" --text="Enter delay in minutes:")"
seconds=`echo "$delay *60" | bc`
count=1
if [ $seconds -le 100 ]; then
  pc=1
  else
  pc=`echo "$seconds/100"| bc`
fi
## Find all files and folders in the current directory, sort
## them and iterate through them
find "$d1" -maxdepth 1 -type f | sort -n | while IFS= read file; do
    ## Set the flag back to 0 for each file
    flag=0;
    ## The flag will be 0 until the file is moved
       while [ $flag -eq 0 ]; do
       ## Move the current file to $d2 and increment the counter.
       mv -v "$file" "$d2" && flag=1;
          if [ -z "$(ls -A "$d1")" ]; then
          zenity --info --text "Move Completed"
          else
	  while [ $count -le 100 ]; do 
            count=$(( $count + 1 )); echo "$count"; sleep "$pc"; done | zenity --progress --text ${file##*/} --percentage=0 --auto-close --auto-kill;
          fi
       done;
done

Last edited by Fitch; 03-12-2018 at 08:42 PM.
 
Old 03-13-2018, 12:50 PM   #13
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Fitch View Post
I just want to see the bar creep up, so I know it's working
there is a cp and mv rewrite with progress bars, package is called advcp, and there is a python wrapper around cp and mv, package pycp.
both are not graphical, they display a progress bar in your terminal.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get zenity code if user close zenity window pedropt Programming 4 03-03-2017 12:13 PM
copy files/directory and show it by progress bar (zenity/kdialog) DoME69 Programming 8 05-07-2015 09:59 AM
[SOLVED] zenity - hiding hidden files from file selections josephj Programming 5 10-15-2010 01:53 PM
moving files from a location to other, preventing to move incomplete files pogo123 Programming 8 11-14-2008 06:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration