Ashish Thukral Ashish Thukral - 1 year ago 53
Bash Question

mac crontab open application behaves differently than opening from Dock

i wrote a shell script that checks if Microsoft Lync is running and Opens the app if not running. if i execute the shell script directly from bash terminal, it opens up Lync and as Remember Username/password is clicked it logs on fine.
the same script i entered in crontab entries to be run every minute so i can start Lync if not running already. But for some reason when the Lync is opened from this crontab script execution, the Lync application does not auto sign-in and asks me for the Lync password.
why is this behavior different ?

crontab entry -

* 9-17 * * 1-5 $HOME/


LYNC_PID=$(launchctl list | grep "Lync" | awk '{print $1}')

if [ "$LYNC_PID" = "" ]
echo "Lync not running"

ERROR_REPORTER_PID=$(ps -ef | grep -i "[m]icrosoft error reporting" | awk '{print $2}')
if [ "$ERROR_REPORTER_PID" != "" ]
echo "Killing Microsoft Error Reporter"
echo "Starting Lync"
open /Applications/Microsoft\


Answer Source

The Dock and other interactive commands running in a session have access to the session's information, including your keyring and the screen. Cron has none of this. Attempting to run interactive programs from crontab is doomed to fail, in pesky corner cases if not outright in the regular main usage scenario.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download