Ashish Thukral Ashish Thukral - 17 days ago 5
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.sh


#!/bin/bash

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

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

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

fi

Answer

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.

Comments