Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

[Beginer] How can I have follow the stat of rsync

Dear All,


I working hard to make my firts backup script with Apple script.


I have a rsync command which copy the file from a place toenother one.


While the rsync process is running, I would like to have the % of the process in order to let the user to know where is the state.

Is there a way to do it and how?


I can use somethink else than rsync, but be aware that I ahev to use smb protocole because my data are synchronized from Apple to Linux or Windows server.


Any suggestion?


Cheers

Pierre

Posted on Jan 18, 2012 5:19 AM

Reply
Question marked as Best reply

Posted on Jan 18, 2012 9:26 AM

There's no direct way to get the progress of your rsync command - once AppleScript calls the do shell script command it has no visibility into what that command is doing until it's finished.


There is one workaroud, but it takes some effort. You can execute the shell command in the background - this passes control back to your AppleScript while the shell command is still running. In addition, you can redirect the output of the shell command to a file and your AppleScript can read that file to determine the progress of the command. It's not trivial to do, but it's about the only option you have.


-- run the command

set thePID to do shell script "/path/to/lengthy/process &> /var/tmp/my.out & echo $!"

-- grab its ID

set processIsRunning to true

-- repeat while it's running

repeat until processIsRunning is false

tell application "System Events"

try


-- if this works, the process is still running

do shell script "ps -p " & thePID


-- so grab the last line of the output file

set progress to last paragraph of (read POSIX file "/private/var/tmp/my.out")

on error


-- if we get here the process isn't running, so clean up

set processIsRunning to false

do shell script "rm /var/tmp/my.out"

end try

end tell


-- show the output


display dialogprogress

end repeat

2 replies
Question marked as Best reply

Jan 18, 2012 9:26 AM in response to pierrot10

There's no direct way to get the progress of your rsync command - once AppleScript calls the do shell script command it has no visibility into what that command is doing until it's finished.


There is one workaroud, but it takes some effort. You can execute the shell command in the background - this passes control back to your AppleScript while the shell command is still running. In addition, you can redirect the output of the shell command to a file and your AppleScript can read that file to determine the progress of the command. It's not trivial to do, but it's about the only option you have.


-- run the command

set thePID to do shell script "/path/to/lengthy/process &> /var/tmp/my.out & echo $!"

-- grab its ID

set processIsRunning to true

-- repeat while it's running

repeat until processIsRunning is false

tell application "System Events"

try


-- if this works, the process is still running

do shell script "ps -p " & thePID


-- so grab the last line of the output file

set progress to last paragraph of (read POSIX file "/private/var/tmp/my.out")

on error


-- if we get here the process isn't running, so clean up

set processIsRunning to false

do shell script "rm /var/tmp/my.out"

end try

end tell


-- show the output


display dialogprogress

end repeat

[Beginer] How can I have follow the stat of rsync

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.