LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   copy files/directory and show it by progress bar (zenity/kdialog) (https://www.linuxquestions.org/questions/programming-9/copy-files-directory-and-show-it-by-progress-bar-zenity-kdialog-4175541762/)

DoME69 05-06-2015 05:12 AM

copy files/directory and show it by progress bar (zenity/kdialog)
 
Hi,

I wrote script tcsh to copy files/directory.
what is wrong and why zenity not open?

Code:

#!/bin/tcsh -f

set src = `du -s $1 | awk '{print$1}'`
set des = "0"

cp -rp $1 $2
while ($src >> $des)
set des = `du -s $2 | awk '{print$1}'`


echo `lua -e "print ( $des/$src *100 ) "`
echo $src
echo $des

end | zenity --progress --percentage=0 ;


millgates 05-06-2015 09:50 AM

Hello,
I am not very familiar with tcsh, but:

1/ First, you copy the files, _THEN_ you run some loop doing what?
2/ Doesn't tcsh use double quotes around parameters?
3/ What's the condition for the while loop? $src >> $des. Is that a bit shift?

Habitual 05-06-2015 09:50 AM

Quote:

Originally Posted by DoME69 (Post 5358631)
Code:

#!/bin/tcsh -f

set src = `du -s $1 | awk '{print$1}'`
set des = "0"

cp -rp $1 $2
while ($src >> $des)
set des = `du -s $2 | awk '{print$1}'`


echo `lua -e "print ( $des/$src *100 ) "`
echo $src
echo $des

end | zenity --progress --percentage=0 ;


Try it in bash using "set -x" like so:
Code:

#!/bin/bash
set -x

set src = `du -s $1 | awk '{print$1}'`
set des = "0"

cp -rp $1 $2
while ($src >> $des)
set des = `du -s $2 | awk '{print$1}'`


echo `lua -e "print ( $des/$src *100 ) "`
echo $src
echo $des

end | zenity --progress --percentage=0 ;

run it from shell and watch the debug output for errors.
Let us know.

DoME69 05-07-2015 12:44 AM

Quote:

Originally Posted by millgates (Post 5358711)
Hello,
I am not very familiar with tcsh, but:

1/ First, you copy the files, _THEN_ you run some loop doing what?
2/ Doesn't tcsh use double quotes around parameters?
3/ What's the condition for the while loop? $src >> $des. Is that a bit shift?

1. loop should get the progress number and show it at zenity.
2. no error found so i guess yes.
3. don't understand the problem

bash not work for me and i still want to use tcsh.

can anyone help?

millgates 05-07-2015 04:11 AM

Quote:

Originally Posted by DoME69 (Post 5358977)
1. loop should get the progress number and show it at zenity.

Progress of what? The copying is already finished by the time the loop starts.

Quote:

Originally Posted by DoME69 (Post 5358977)
2. no error found so i guess yes.

My point is, if quoting in tcsh works as it does in bash, which I assume it does, your script will break whenever the filenames contain spaces. So you should put double quotes around all the variables like "$1", "$2", etc. If I'm wrong pleas somebody correct me.

Quote:

Originally Posted by DoME69 (Post 5358977)
3. don't understand the problem

The problem is that the >> operator is a right shift (shifts bits in a variable to the right) in most languages (or a redirection). I believe in this context it would be the right shift. That doesn't make sense, maybe you meant $src > $des?

Habitual 05-07-2015 06:41 AM

Quote:

Originally Posted by DoME69 (Post 5358977)
bash not work for me and i still want to use tcsh.

can anyone help?

I tried to help and you told me what you didn't want.
Now I don't want to help you.
If you are not willing to take direction, why are you asking for help?

You're welcome, btw.

schneidz 05-07-2015 07:24 AM

maybe using dd you can redirect its progress to be prompted to zenity.

genss 05-07-2015 07:39 AM

Code:

#! /bin/sh
rm sometmp
dd if=/dev/urandom of=/dev/null 2>&1 > sometmp &
DD_PID=$!

while true
do
    /bin/kill -10 $DD_PID || exit
    sleep 1
    cat sometmp
done

rm pipe

too sleepy for context
(and idk zenity)

michaelk 05-07-2015 09:59 AM

As stated your copy command completes before the loop starts and the syntax for zenity is incorrect. I would base the progress on number of files copied versus directory size. The following is psuedo bash but I think it gets the basic idea across.

Code:


for (( x<$no_files_to _copy )); do
  cp $file $destination
  echo "$(( (x * 100) / no_files_to_copy ))"
done | zenity --progress \
  --title="Copying Files to $destination" \
  --text="$file" \
  --percentage=0



All times are GMT -5. The time now is 09:42 PM.