Skip to content
Advertisement

Background rsync and pid from a shell script

I have a shell script that does a backup. I set this script in a cron but the problem is that the backup is heavy so it is possible to execute a second rsync before the first ends up. I thought to launch rsync in a script and then get PID and write a file that script checks if the process exist or not (if this file exist or not). If I put rsync in background I get the PID but I don’t know how to know when rsync ends up but, if I set rsync (no background) I can’t get PID before the process finish so I can’t write a file whit PID.

I don’t know what is the best way to “have rsync control” and know when it finish.

My script

JavaScript

Can anybody help me?!

Thanks in advance !! 🙂

Advertisement

Answer

JavaScript
  • pidof finds the pid of a process
  • -x tells it to look for scripts too
  • ${sScriptName} is just the name of the script…you can hardcode this
  • wc -w returns the word count by words
  • -gt 2 no more than one instance running (instance plus 1 for the pidof check)
  • if more than one instance running then exit script

Let me know if this works for you.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement