Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX bash "sleep"

Tags:

bash

shell

macos

I'm trying to suspend or "sleep" a specific line in a bash script running in OSX. The script runs at startup before login. I'm not seeing the results I'm expecting. In other words no matter what time I specify after "sleep" the script still moves right along with no delay what so ever. However when I run the script after login, the "sleep" command seems to work just fine.

Is it possible that the command file "sleep" isn't in the path before login or before my script runs? Would it help if I placed the path to sleep before the command? If so where does "sleep" live?

Is there another approach or alternative command I could try?

Thanks

#!/bin/bash

#Create the bin directory
sudo mkdir /usr/local/bin

sleep 10

#Copy the files to the Hard Drive
sudo cp /Volumes/NO\ NAME/adbind.bash /usr/local/bin/adbind.bash
sudo cp /Volumes/NO\ NAME/com.sjusd.adbind.plist /Library/LaunchDaemons/com.sjusd.adbind.plist

#Fix permissions
sudo chown root:wheel /usr/local/bin
sudo chmod 755 /usr/local/bin
sudo chown root:wheel /Library/LaunchDaemons/com.sjusd.adbind.plist
sudo chmod 755 /Library/LaunchDaemons/com.sjusd.adbind.plist

exit 0

Dang tough crowd I got a minus 1 LOL

like image 873
Chuck Avatar asked Oct 09 '12 15:10

Chuck


2 Answers

This might be a little late, but it seems that sleep on OS X doesn't work with quantifiers (m,h, ...). Official Apple documentation

So "sleep 5m" is the same as "sleep 5". If you want 5 minutes, you have to use "sleep 300"

like image 89
Webbie Avatar answered Sep 29 '22 01:09

Webbie


If you run which sleep, you can get the path to 'sleep' on your system. I get /bin/sleep.

At this point, you have a couple of options:

you can specify the path to sleep when you call it

#!/bin/bash
# script before sleep ...
/bin/sleep
# ... after sleep

or you can add the path to your $PATH variable within your script before you call it.

#!/bin/bash
PATH="$PATH:/bin"
# script before sleep ...
sleep
# ... after sleep
like image 36
Barton Chittenden Avatar answered Sep 29 '22 00:09

Barton Chittenden