Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Setting up a Cron job with OS X Leopard

Setting up a Cron job with OS X Leopard
Thread Tools
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
May 8, 2008, 02:16 PM
 
I have been looking over a cron job that will Bless the computer with the Windows partition and set as the startup disk, but I'm not sure where I need to put this script if a script is what i need to make or not.

I went to "crontab -e" in terminal but not sure how to set the time to have the computer run the script.

Here a copy of the script:
#!/bin/bash
# Adds necessary cron entries to clients so that systems reboot back into Windows at 6 AM
rm -f crontab.file.$admin
crontab -u $USER -l > crontab.file.$admin
echo "15 12 * * * /sbin/reboot" >> crontab.file.$admin
echo "30 05 * * * /usr/sbin/bless -mount /Volumes/Windows/ -legacy --setBoot" >> crontab.file.$admin
echo "00 06 * * * /sbin/reboot" >> crontab.file.$admin
crontab -u $admin crontab.file.$admin
I found this here: Bombich Software Forums - View topic - Dual boot - Windows scriptable startup disk?

Thanks,
.
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
May 8, 2008, 02:47 PM
 
What do you need help with, the syntax for specifying a time? It's minutes, hours, days, months, weekday, command, in that order.

Do you have something that sets the value of $admin? What is your problem with the script?
     
carterx  (op)
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
May 8, 2008, 02:54 PM
 
Originally Posted by besson3c View Post
What do you need help with, the syntax for specifying a time? It's minutes, hours, days, months, weekday, command, in that order.

Do you have something that sets the value of $admin? What is your problem with the script?
For setting the time, do I remove what is in the terminal as such in this snapshot I just did and then add the location of the script for bless the computer to then have it restart to the Windows partition?

Snahshot here:
http://www.filedropper.com/cron1
     
Junior Member
Join Date: Aug 2005
Status: Offline
Reply With Quote
May 15, 2008, 06:38 PM
 
Not sure why you want the computer to reboot at 12:15pm, but I can help with the rest.

Where to put the script: Anywhere. This script adds timed todo items (cron jobs) to your computer. Run it once and it's set. You can delete the script after that.

Changing the time: Each line in the crontab looks like this:
Mi H D Mo W CMD
So when the computer's time and date match the first five parameters (i.e. it is H:Mi o'clock on the Dth day of Mth month and the day of the week is W) the CMD will run. Using a * for any of these entries (except CMD) will mean always. The script you provide tells the computer to (in chronological order) Bless at 5:30am. Reboot at 6:00am. Reboot at 12:15pm. If you want to change the time this happens, replace these times with those you want. (24 hour time. Run "man crontab" for more info)

NB: You probably don't want to change $USER to $admin. $USER is something that is known to the computer. It doesn't matter if you are an admin or not.

If you want to reboot into Windows automatically every day at 2:11pm use this:
#!/bin/bash
rm -f crontab.file.$USER
crontab -u $USER -l > crontab.file.$USER
echo "0 14 * * * /usr/sbin/bless -mount /Volumes/Windows/ -legacy --setBoot" >> crontab.file.$USER
echo "11 14 * * * /sbin/reboot" >> crontab.file.$USER
crontab -u $USER crontab.file.$USER
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
May 15, 2008, 07:25 PM
 
Instead of using the cronjob, yuo can also put the executable script into /etc/periodic/daily/.

It will be executed once every day, by default at 3:15am (IIRC).

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
May 15, 2008, 07:55 PM
 
The script will need executable permissions too, just in case this was not known.
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
May 15, 2008, 08:12 PM
 
'Tis true.

But I forgot to mention one great advantage: scripts in /etc/periodic/daily/ will run as admin.
AFAIK, it's quite a pain to get cron jobs to run as admin. Or am I confusing something ?

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
May 15, 2008, 08:18 PM
 
Scripts in there run as root, not as an admin user on the system. In this case, this is an appropriate use of this since admin users can't bless and reboot anyway non-interactively.
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
May 15, 2008, 08:20 PM
 
Ah, my bad. Wasn't sure if it was root. Well, I mean, doesn't make a lot of difference, it just works

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
May 16, 2008, 09:50 AM
 
Originally Posted by davidbk1 View Post
To made a script executable use the following in terminal:
chmod 755 /path/to/file
This also makes this same script executable by everybody on your machine, which may not be what you want to do. chmod 700 will make the script readable, writable, and executable by the owner or root, which is probably a safer bet.
     
Junior Member
Join Date: Aug 2005
Status: Offline
Reply With Quote
May 16, 2008, 10:51 AM
 
Just another note. If you want to do as turtle suggested, this is not the script you want to put in there. This script sets up your cronjobs and needs to be run only once. Use the following in the daily folder (you're stuck with the time as far as I know):
#!/bin/bash
/usr/sbin/bless -mount /Volumes/Windows/ -legacy --setBoot
/sbin/reboot

To made a script executable use the following in terminal:
chmod 755 /path/to/file
     
carterx  (op)
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
Jul 2, 2008, 12:25 PM
 
Sorry I have not posted back to this topic, been busy and had other projects show up.

Ok so read over the topic thread. What tends to be the best method for blessing the Windows OS. I see you can use cron or a daily script.

As I need to have the computer bles the WINDOWS OS and reboot at a specific time each night, would the cron be best?

The reason is that at about 11:50pm, the computer will need to be booted into the WINDOWS OS so that when 12:00am rolls around, the regular college Windows duties will run through our system which has the computer thaw the computers, restart, run updates, then re freeze. Once re frozen, they will then have an AutoIT script/.exe on the WINDOWS side bless the OS X system and restart the computer to be back to the BootPicker screen for the morning.

Also, on another topic but sorta the same, anyone ever use AutoIT. I have not had time yet to sit down with someone from work here to show me how to set the AutoIT script/.exe to run at specific times like the cron script will do?

Many thanks,
     
carterx  (op)
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
Jul 2, 2008, 12:50 PM
 
Here is what I have for the cron job should stand for:

11:50pm everyday, every month, every week run by root?

Now, not sure where this info get entered ..... thought it was into terminal?


user% cat /etc/crontab
# $NetBSD: crontab,v 1.13 1997/10/26 13:36:31 lukem Exp $
#
# /etc/crontab - root's crontab
#
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log

#min hour mday month wday user command
50 23 * * * root sh /etc/daily/blesswindows.sh
     
carterx  (op)
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
Jul 7, 2008, 10:46 AM
 
Originally Posted by turtle777 View Post
Instead of using the cronjob, yuo can also put the executable script into /etc/periodic/daily/.

It will be executed once every day, by default at 3:15am (IIRC).

-t
Ok, so lets see if I'm reading this right. If I put the following script
#!/bin/bash
/usr/sbin/bless -mount /Volumes/Windows/ -legacy --setBoot
/sbin/reboot
into /etc/periodic/daily/ it will run and set/bless the windows partition?

If this script is in this location, how do I set when the script/daily runs? You say that by default it's 3:15am. I want to set it to 11:50pm every night.

Thanks,
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 11:05 AM
 
The only way to know hat it has run is to add some output to a log file.

E.g.

Code:
echo `/bin/date`" : last time executed" >> ~/log.txt
There are ways to change the time of the execution to something other than 3:15. I have never done that, you'd have to google it.

-t
     
carterx  (op)
Mac Enthusiast
Join Date: Jan 2007
Location: Canada
Status: Offline
Reply With Quote
Jul 7, 2008, 11:15 AM
 
Well, sounds like setting a cron will be best.

I have the script
#!/bin/bash
/usr/sbin/bless -mount /Volumes/Windows/ -legacy --setBoot
/sbin/reboot
which at the moment is on my desktop. Where does this need to go?

Second, I have searched online and I'm still unsure how to set the cron script. I have my info
user% cat /etc/crontab
# $NetBSD: crontab,v 1.13 1997/10/26 13:36:31 lukem Exp $
#
# /etc/crontab - root's crontab
#
SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log

#min hour mday month wday user command
50 23 * * * root sh /etc/daily/blesswindows.sh
Just not sure how to open this up and set.

I was told to use Lingon to get this all setup, but can't figure out how to get it all done.

Tks,
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 11:21 AM
 
caterx, cron does NOT run things in root / admin, AFAIK.

If you need things to be done by an admin, use my method. It will run as root.

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 11:45 AM
 
Crontabs placed in /etc/crontabs will be picked up, but these may be replaced with a future OS update. It would be better to enter these into root's crontab, which you can do via the following:

sudo crontab -e
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 11:46 AM
 
Originally Posted by carterx View Post
Well, sounds like setting a cron will be best.

I have the script


which at the moment is on my desktop. Where does this need to go?

Second, I have searched online and I'm still unsure how to set the cron script. I have my info


Just not sure how to open this up and set.

I was told to use Lingon to get this all setup, but can't figure out how to get it all done.

Tks,

Your bash script can be stored anywhere... I'd recommend /usr/local/sbin, since this would likely be in your shell's path, and since this is a logical place to put it in terms of organization.
(Last edited by besson3c; Jul 7, 2008 at 11:54 AM. )
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 11:49 AM
 
Originally Posted by besson3c View Post
Your bash script can be stored anywhere... I'd recommend /usr/local/sbin, since this would likely be in your shell's path, and since this is a local place to put it in terms of organization.
Is /usr/local/sbin safe from future OS updates ?

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 11:54 AM
 
Originally Posted by turtle777 View Post
Is /usr/local/sbin safe from future OS updates ?

-t

Yes, as long as the file isn't named something that is identical to what Apple might distribute in the future. I doubt that Apple does any file comparison like this (either via checksum or diff), it will probably just brainlessly overwrite or rename the old file if it were to encounter an existing file of the same name/path. However, if you called the script "bless_companylabs.sh" or something, the chances of Apple overwriting this with something of their own are basically none.
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 11:55 AM
 
But why would Apple put anything in /usr/local/sbin ?

Isn't this directory only used for manual, user installed files ?

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 11:59 AM
 
Originally Posted by turtle777 View Post
But why would Apple put anything in /usr/local/sbin ?

Isn't this directory only used for manual, user installed files ?

-t
In theory, but I believe Apple puts stuff in there that ships with OS X but is not developed by Apple - i.e. preinstalled add-on software provided by Apple. In /usr/local/bin on my machine I see emacs, perl, gcc, openssl, in addition to some stuff I know I installed myself (e.g. wine, sshfs, growlnotify).
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 12:00 PM
 
Interesting. I only have self-installed stuff in it.

Is that extra stuff from the Developer's DVD ?

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 12:03 PM
 
Originally Posted by turtle777 View Post
Interesting. I only have self-installed stuff in it.

Is that extra stuff from the Developer's DVD ?

-t
I doubt it...

Do a:

which emacs

what is the output you get?
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 12:06 PM
 
It looks like the versions of emacs, perl, gcc, etc. I have in /usr/local/bin are just symlinks to their parent in /usr/bin. Maybe Apple created these for some reason? *shrug*
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 12:10 PM
 
/usr/bin/emacs

I don't have the symlinks that you seem to have.
Why ?

-t
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jul 7, 2008, 12:14 PM
 
What do you have in /usr/local/bin?
     
Clinically Insane
Join Date: Jun 2001
Location: planning a comeback !
Status: Offline
Reply With Quote
Jul 7, 2008, 09:32 PM
 
Originally Posted by besson3c View Post
What do you have in /usr/local/bin?
On my Mac mini, neither /usr/local/bin/ nor /usr/local/sbin/ exist.

On my iMac, I have the following:

/usr/local/bin/

-rwxr-xr-x 1 root wheel 47K Feb 21 10:00 fuse_wait
-rwxr-xr-x 1 root wheel 112K Feb 21 10:00 ntfs-3g
-rwxr-xr-x 1 root wheel 43K Feb 21 10:00 ntfs-3g.probe
-rwxr-xr-x 1 root wheel 85K Feb 21 10:00 ntfscat
-rwxr-xr-x 1 root wheel 101K Feb 21 10:00 ntfscluster
-rwxr-xr-x 1 root wheel 98K Feb 21 10:00 ntfscmp
-rwxr-xr-x 1 root wheel 94K Feb 21 10:00 ntfsfix
-rwxr-xr-x 1 root wheel 183K Feb 21 10:00 ntfsinfo
-rwxr-xr-x 1 root wheel 89K Feb 21 10:00 ntfsls
lrwxr-xr-x 1 root wheel 74B Mar 23 05:10 pgpdisk -> /Library/Application Support/PGP/PGP Engine.app/Contents/Resources/pgpdisk

/usr/local/sbin/

-rwxr-xr-x 1 root wheel 315K Feb 21 10:00 mkntfs
lrwxr-xr-x 1 root wheel 111B Mar 23 05:10 mount.ntfs-3g -> /Users/erik/devel/NTFS-3G_Package/Components/ntfs-3g/patched/ntfs-3g-1.2216/build_stable~/usr/local/bin/ntfs-3g
-rwxr-xr-x 1 root wheel 140K Feb 21 10:00 ntfsclone
-rwxr-xr-x 1 root wheel 85K Feb 21 10:00 ntfscp
-rwxr-xr-x 1 root wheel 81K Feb 21 10:00 ntfslabel
-rwxr-xr-x 1 root wheel 173K Feb 21 10:00 ntfsresize
-rwxr-xr-x 1 root wheel 155K Feb 21 10:00 ntfsundelete

Funny thing is, /Users/erik/ doesn't even exist on my iMac

-t
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 05:30 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2