diff --git a/scripts/packages/automated_cleanup.rb b/scripts/packages/automated_cleanup.rb
index ce8a23315a916d44085ca83a23cc2e96cb4fb3ef..8b2803100e057b28e894f0177e7d4d04f1b54df2 100755
--- a/scripts/packages/automated_cleanup.rb
+++ b/scripts/packages/automated_cleanup.rb
@@ -96,7 +96,7 @@ def timed(task)
   puts "#{task} finished in #{Time.now - start} seconds.\n"
 end
 
-if $0 == __FILE__
+if $PROGRAM_NAME == __FILE__
   options = {
     dry_run: false
   }
diff --git a/scripts/review_apps/automated_cleanup.rb b/scripts/review_apps/automated_cleanup.rb
index d8b46556b4a7b1ebca83a46249142772cce3e914..cfe7a679f9e72c163f44f63ae0209ee562a83423 100755
--- a/scripts/review_apps/automated_cleanup.rb
+++ b/scripts/review_apps/automated_cleanup.rb
@@ -265,7 +265,7 @@ def timed(task)
   puts "#{task} finished in #{Time.now - start} seconds.\n"
 end
 
-if $0 == __FILE__
+if $PROGRAM_NAME == __FILE__
   options = {
     dry_run: false
   }