I have a piece of code in my application which i use to create a crontab. When i compile and run it from my xcode, the code works perfectly fine without errors and places a cronjob at the time specified.
NSDictionary *error = [NSDictionary new];
NSString *script = @"do shell script \" crontab -l > mycron ; echo '30 11 * * * cd /Applications/PagePlannerMac && ./JunkDataDeleteScript.sh >> /Applications/PagePlannerMac/scriptlogs.log' >> mycron ; crontab mycron ; rm mycron\" ";
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
if ([appleScript executeAndReturnError:&error]) {
NSLog(@"success!");
} else {
NSLog(@"failure!");
}
Basically what the code does is it executes a shell command to create the cron.
When i compile and get the dmg file of my application, install and test. The cron does not execute, there are no errors or crashes. Not sure what is causing it to fail. Any help is apprecitated.
Make a shell script:
#!/bin/sh
( \
cd /Applications/PagePlannerMac && \
/path/to/JunkDataDeleteScript.sh | tee -a \
>> /Applications/PagePlannerMac/scriptlogs.log && \
crontab -l && echo '30 11 * * * /path/to/this/script.sh' \
) | sort | uniq | crontab
Add the script the first time to crontab:
30 11 * * * /path/to/this/script.sh
When it runs, the following happens:
/Applications/PagePlannerMac
.JunkDataDeleteScript.sh
./Applications/PagePlannerMac/scriptlogs.log
.crontab
file to stdout
.JunkDataDeleteScript.sh
output, current crontab
, and the echo to stdout
.crontab
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.