Many time we have been faced this issue when we want to schedule any task on our mac servers. There is one inbuilt tool crontab but it doesn't work as per our expectations. So its better to use launchd to schedule tasks, it perfectly works in all scenarios. I have explained a simple task below which i used to take backup of DeployStudio server scripts and workflows and save them on a remote location.
1. Create a backup Application in Automator. I have pasted him after some editing so you can change it as per your requirements.
First part is to mount the shared folder.
Second part is to copy the scripts and workflows, then unmount the volume.
2. Create a script to run this application.
Copy the below mentioned command in a script and change it as per your location of the application which you have created in first step and save it as per your naming style, here i have saved it as Script.sh.
3. Create a PLIST file as per your requirement and run the application to initiate the backup.
4. Now make it as service and initiate it.
Use below mentioned command to load and start the plist
ALL DONE... By this way to can create application to do any task and schedule it as per your choice.
Put your comments if you have any questions.
1. Create a backup Application in Automator. I have pasted him after some editing so you can change it as per your requirements.
First part is to mount the shared folder.
Second part is to copy the scripts and workflows, then unmount the volume.
2. Create a script to run this application.
Copy the below mentioned command in a script and change it as per your location of the application which you have created in first step and save it as per your naming style, here i have saved it as Script.sh.
open /YourLocation/Backup.app
3. Create a PLIST file as per your requirement and run the application to initiate the backup.
I have mentioned 86400 seconds in the plist so that it will run in every 24 hours. Saved this plist as "deploystudio.backup.plist"<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>Label</key><string>deploy studio.backup</string><key>ProgramArguments</key><array><string>/YourLocation/Script.sh</string></array><key>StartInterval</key><integer>86400</integer></dict></plist>
4. Now make it as service and initiate it.
launchctl load ~/Library/LaunchAgents/deploystudio.backup.plist launchctl start deploystudio.backup.plist
Use below mentioned command to unload and stop the plist
launchctl unload ~/Library/LaunchAgents/deploystudio.backup.plist launchctl stop deploystudio.backup.plist
ALL DONE... By this way to can create application to do any task and schedule it as per your choice.
Put your comments if you have any questions.
0 comments:
Post a Comment