Cron-based terminal job doesn't start until screen unlocked (sometimes) - ruby

I have a cron job whose command line looks like:
30 5 * * * osascript -e 'tell application "Terminal" to do script "bash-script-file"'
FWIW the base script file sets some environment variables and then runs a Ruby program.
Prior to last week, most days this ran just fine, but occasionally (~ twice/month) it would hang until I either unlocked the screen or attached remotely to the system. At that time I would see a terminal screen with a message about new mail and a command line prompt with the bash-script-file on it. At that point, I could wait and the script would proceed to run normally. I have checked System Settings and the computer is set to sleep never. I'm not locking the screen (instead allowing it to go to sleep), and of course I have the screen saver locked, requiring a password to wake up.
Last week (about five days ago), I added a second cron job of the same form (running another bash script that started another Ruby program), and since then, both jobs have hung every day until I attached remotely. What is causing this? What can I do to resolve it?
tl;dr cron-scheduled terminal jobs are hanging until the screen unlocks.

Related

Windows CMD/Power Shell sleep's when i do not interact

I use the power shell a lot to run react-native aplications and Android emulators. But every time i have to open the shell and press enter to wakeup the shell, because aparrently it stops running or lose priority when i do not interact with it for some time.
So, there's some way to prevent the cmd from stop processing my tasks?
Other people have reported this as an issue but it turned out to be user error. I can only assume that you have the same problem.
Chances are that quickedit mode is on and you have somehow clicked in the window thus freezing the process.
See this post on serverfault
And this post on MS technet

Is There a Way to Auto-close 'App Has Stopped Responding' Messages?

I have a simple batch script running constantly on a Windows 10 PC at work that performs relatively simple tasks over and over again throughout the day, basically testing certain server diagnostics while I'm working on it.
Every once in a while, the program will crash, so I have another program I downloaded that will auto-start up the program if it does crash and close.
However, there is one scenario where instead of the program just crashing and closing completely, a message box will pop up saying the program has stopped responding, with a 'Close Program' button. In this case, the auto-start program I have thinks the program is still running, so it won't attempt to re-run the batch script.
Is there a way to auto close the program when it crashes this way, or something that will automatically click the 'Close Program' button for me when it appears?
I suspect the messages comes out when the main thread hangs for too long. It may be cleaner to spawn another thread to take care of expensive / slow computation, Windows should not bother to kill the main thread (and your program) in first place like that.

OS X LaunchAgent - Run when desktop ready?

I've created a bash script which does some complex stuff, including some bits of Applescript which involves clicking pop ups, its to run on every new account created on the machine to set up some browser extensions for users (Adblock etc)
The script runs when manually invoked just fine, but when put as a LaunchAgent is erratic at best. It seems to run whilst the create account login/password screen is up - it opens a welcome PDF for a start off and sometimes when you log in, preview is already open without the file.
Othertimes you log in and nothing happens for a good 50 seconds. Occasionally its behaviour is erratic too.
The script needs to run as a launchagent as it runs once per new account - the script actually deletes the launchagent plist at the end so it can't run again. Is there anyway to delay the running of the script to have it start once the desktop is fully loaded? Perhaps once the dock has appeared. I'm going to assume its trying to run too early, it can't open Preview or Safari, it tries to delete the plist which is in use and then just ends up in a confused loop. Obviously not the cleanest way to run.

Applescript to disable scheduled shutdown if #%n app is running?

Is there an Applescript somewhere that can tell the Energy Saver shutdown scheduler in OSX 10.8 "don't shut down the computer if #%n app is running?" I use the Energy Saver scheduler to shut down my machine in the evenings and power back up in the mornings, but sometimes I need to let an app run overnight.
I know about Caffeine, but I want something automated, hence the script - I want the script to tell the Energy Scheduler, "Hey, #%n app is running, don't shut down tonight" without requiring me to do anything.
Thanks!
One way you can do this is not use the Energy Saver shutdown scheduler at all, and instead use the Calendar application to schedule when to run this little script to conditionally shutdown the system.
In this example, I have set this up for iTunes, but you can change this to any application you require.
Use the Applescript Editor to create and save a script like this:
set myapp to "iTunes"
if application myapp is not running then
tell application "Finder" to shut down
end if
Open the Calendar application and set up a new event which occurs whenever you want the scheduled shutdown to occur e.g. every day at 9pm. In the "New Event" box, you can change the "alert" field to "Open File", then change the file to be opened to the script that you just saved.
The script should run when you have scheduled it, and only shutdown the system if iTunes (or whichever application you want) is not running.
Note that tell application "Finder" to shut down will do a "careful" shutdown - i.e. if there are any other applications which don't want to be shutdown, then the shutdown will be cancelled.

Getting blank (black) screenshot with automated screen capture using task scheduler

I am trying to troubleshoot a software bug in which we think an app may not be launching every time it is called. To test this, I created a series of scheduled tasks to launch the app, take a screenshot, and then close the app. These tasks are all run through .bat files.
Everything works fine except for the screenshots. When run as a scheduled task, the .jpg from the screen capture always shows a black box. If I execute the .bat file normally, the screenshot looks fine.
I am using nircmd to send the screen capture command and save it to a folder. The command I am using is as follows:
nircmd.exe savescreenshot "C:\File Path\"~$currdate.MMddyyyy$-~$currtime.HHmmss$.jpg
I am using Windows 7.
The task created is probably running in its own logon session, even if it is running as the same user.
Make your scheduled task run as the currently logged on user.
Keith Brown wrote an old but still valid detailled explaination of the logon session SID. The relevant part is at the middle, under "http://www.microsoft.com/msj/0599/security/security0599.aspx"
You can also poke around the access rigths with EnumWinStaGui.

Resources