Author Topic: Questions about Backup-Crintab-Launchd  (Read 2343 times)

Christian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Questions about Backup-Crintab-Launchd
« on: July 25, 2014, 08:29:13 AM »
First of all thank you very much for this great book! It really is fantastic and I cannot await the other three books coming! ;D ;D ;D

Now my question: I have implemented the DNS, DHCP and OD backup script and the outcome is as follows: OD works well manually and automated with crontab or launchd, while both DNS and DHCP backup scripts only work manually. This means, the written scripts for automating the process as pointed out in the book work well if they are called via the terminal as: sudo path/to/thescript, but if I put the same to crontab or launchd the scripts create an empty file (in both cases). User is set to root in crontab. I have tried everything, even on different machines, but I can definitely not figure out what is going on. Help would be great.

Best regards
Christian

Reid Bundonis

  • Administrator
  • Full Member
  • *****
  • Posts: 107
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #1 on: July 25, 2014, 09:35:31 AM »
Thanks so much for the comments.  I will look into this today and see what I can find.

I recall running in the 0k DNS file thing a while back but don't recall the solution.  Check back in a bit.

Reid Bundonis

  • Administrator
  • Full Member
  • *****
  • Posts: 107
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #2 on: July 25, 2014, 10:29:18 PM »
Well, you clearly have found a bug or at least something I can not explain at this time.  Still investigating.  But under 10.9.4 with Server 3.1.2 I am seeing the same issue.  Scripts automated either through cron or launchd is producing 0k files.  Ouch.

Still looking into this.  Hmm

Christian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #3 on: July 26, 2014, 08:24:15 AM »
Thank you very much for the quick reaction! Great!

I have been trying a lot, but I could not figure out what is going on. At least up to now. I am curios what your outcome will be.

Reagrds
Christian

Reid Bundonis

  • Administrator
  • Full Member
  • *****
  • Posts: 107
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #4 on: July 30, 2014, 09:52:52 PM »
Sorry for this taking so long to get back.  But dang!  You found a good one here.  I've taken a look and this appears to have started at some point in 10.8.5.  I don't have any 10.9.0 through 10.9.2 systems out there any more but 10.9.3 and 10.9.4 are doing the same 0k output file issue. 

As you mentioned, this only happens when called by either cron or launchd.  If I run the script manually or execute the command, the file is populated as expected.  Huh?

So I thought I would be a wise guy and dump the output to a variable and then print the variable.

#!/bin/bash

myVar=`serveradmin settings dns`

echo $myVar > /SharedFolders/Backup/dns.settings

But that produced nothing as well.  Running it manually works, but automated... nope. 

But AHA!  I got it.  It took an empty house and the Tigers winning but I've got it.

root can not find serveradmin!  That is the simple issue.  I dumped the env when executing via interactive and then when run through crontab.  The difference was this:

Interactive:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin

crontab:
PATH=/usr/bin:/bin
_=/usr/bin/env

Note that your user has the path to serveradmin but root does not.  When the root user executes the command through cron, it can not find server admin.  So the trick is to edit your script to define the full path to the serveradmin command.   

#!/bin/bash

/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin settings dns > /SharedFolders/Backup/dns.settings

That will do it.

Let me know if you have the same success.



Christian

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #5 on: July 31, 2014, 11:29:33 AM »
Thank you very much for digging right into it and finding the solution, I am amazed! It works perfectly well now and is already implemented ;D ;D ;D

Christian

Reid Bundonis

  • Administrator
  • Full Member
  • *****
  • Posts: 107
    • View Profile
Re: Questions about Backup-Crintab-Launchd
« Reply #6 on: July 31, 2014, 11:45:37 AM »
Awesome!  Already updated the 1.5 draft with the fix.  I've been waiting for the next Server.app update but I am guessing it will be a while.  So I think I will submit 1.5 for review at the end of the week.

Thanks for pointing it out.