LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2015, 05:12 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Rep: Reputation: 16
Question 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 ;
 
Old 05-06-2015, 09:50 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
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?
 
Old 05-06-2015, 09:50 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by DoME69 View Post
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.
 
Old 05-07-2015, 12:44 AM   #4
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by millgates View Post
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?
 
Old 05-07-2015, 04:11 AM   #5
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by DoME69 View Post
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 View Post
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 View Post
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?
 
Old 05-07-2015, 06:41 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by DoME69 View Post
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.
 
Old 05-07-2015, 07:24 AM   #7
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 using dd you can redirect its progress to be prompted to zenity.
 
Old 05-07-2015, 07:39 AM   #8
genss
Member
 
Registered: Nov 2013
Posts: 744

Rep: Reputation: Disabled
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)
 
Old 05-07-2015, 09:59 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,749

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
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
 
  


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
show progress bar of sending/copying files via ftp kunalks Linux - Server 3 09-13-2014 07:33 PM
Copy command to show progress bar or status sudo_su Linux - Newbie 5 08-03-2013 04:16 PM
Zenity progress bar mard0 Programming 3 09-22-2012 02:19 PM
how to copy a directory (local) from terminal with progress bar showing Linux.Girl Linux - Newbie 6 08-19-2010 10:00 AM
How the Progress Bar of a copy file/directory process is progressed?(any logic)? kiranprashant Programming 3 03-08-2005 06:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 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