I've got a cron job that essentially looks like this:
*/3 * * * * ruby myscript.rb > /my/location/file.txt
myscript.rb essentially looks like this:
#!/usr/bin/env ruby
sleep(120)
puts "Hello"
So every three minutes I'm running a script that runs for two minutes before writing to STDOUT. (In truth, myscript.rb is making a ton of HTTP requests, not sleeping. My suspicion is that it's the time that matters.)
The strange result is that for some percentage of time, /my/location/file.txt is empty.
It seems as if the script starts, the file is emptied, and only when the script gets to the end is there data written to the file.
This isn't how *nix redirection works though, right?
The ruby process is probably just buffering it's output, to set STDOUT to always flush its output, set sync=true for STDOUT:
STDOUT.sync = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With