![]() |
Sorry about the confusion: The reason why I created two separate scripts was to force the copying to happen after the wget downloading was finished.
In my original script, I had both downloading (wget) and copying (cp) in the same script, and the described events happened when I ran this script first in a terminal and then as a launchd job. Please reply if it is still unclear. As you understand, I solved my problem by creating two separate scripts, but I find it very odd that this happens. At the moment, the problem with disappearing jobs after reboot is more important for me to solve. |
I also have to ask one question. Is there any reason you aren't running these scripts on the server locally via cron? I just think it is more efficient. My hosting company does daily tape back ups of my webroot and home directory on their server. I have a cron job that dumps mysql into a back up file and another one that archives all files and tosses it into another directory in my home folder on my server.
that way I have back ups and they have back ups of my back ups and I don't have to worry about maintaining that many back ups on my own. Plus, if WAN traffic is down somehow between your client machine and your web hosting server, your scripts won't even run. Most hosting companies also provide tools for this built in. So, is there a reason you have to do it this way? |
@tlarkin: That's a good point, I might be able to run the script on the server.
To keep all the backups on the server is not a solution, though, as I'll quickly run out of space. So I do need to download it to my computer at some point. My hosting company does backup my site nightly, but I want to see what files changed when, to make it easier to rollback the site to the state it was before a specific accident happened. |
Quote:
However, you can have them rysnc to your FTP at home on a daily basis and that way everything is ran off the server and not your machine. Launchd items will take up cpu cycles. |
rsync is not installed on the server. I'm pretty sure I tried using rsync before (which I think requires rsync installed on both host and recipient). That's why I ended up using wget instead.
Anyway, I had some hope of learning to use launchd, but it seems it is tricker than I first imagined. My mac mini doesn't do much during the day except serve torrent files and store backups from my other computers, so I don't really mind some CPU time for this backup script. |
Quote:
|
I don't think I can be bothered to get my host to install rsync and then recreate the script to work on the server. My script is very close to do what I want it to do, I just need to figure out how to reload my launchd jobs after reboot.
|
Quote:
|
Solution: Place the job files (backup-download.xml and backup-copy.xml) in the folder ~/Library/LaunchAgents
After a reboot, both jobs are loaded in launchd, visible by running this command: Code:
$ launchctl list |
@tlarkin: You beat me to it. Your solution enables me to keep all the files in the same place as well, which I like.
|
Quote:
1) /Library/LaunchAgents 2) /Library/LaunchDaemons If your agent is loaded into #1 it will load when any user logs into the system. If you put it in #2 it will load at boot up globally with out any user logging in. Both of these run globally, either by log in or just at boot up. The other place you can load them from is: ~/Library/Launchagents These are located in the specific user's home folder and they run only when that user logs in. If you launchctl to load your agent with the -w switch it loads it in launchd permanently, meaning every time you reboot or log in, it will run. |
That's great, thank you.
I cannot get the -w option to work, though. The man page says this: Code:
launchctl load -w Remove the disabled key and write the configuration files back out to disk.If I place the job files in ~/Library/LaunchAgents, they are reloaded after reboot, though. |
Quote:
|
Ok, sorry, then I misunderstood.
I thought the -w option meant I didn't have to place them in one of the 3 folders. If I place them in ~/Library/LaunchAgents I don't have to use the -w option to get them to reload after reboot. On my mac, my user is logged in automatically on reboot, if that matters. I ended up using hard links, so I could still keep the xml files in the same folder as the script and backup files. To create a hard link for the file backup-copy.xml: Code:
$ln ~/Library/LaunchAgents backup-copy.xml |
Quote:
|
Thanks. Now it works. Relief :-)
|
Quote:
http://developer.apple.com/MacOsX/launchd.html You can accomplish some really powerful solutions with launchd. I have created several post config one time run scripts in my images, so the second it boots up, it runs the script then the script deletes itself along with the launch item so it only runs once at first boot and never again. Great way to automate post image configurations on the Mac platform. |
| All times are GMT -5. The time now is 05:32 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.