diff --git a/ChangeLog b/ChangeLog
index 085a54e549e055f27a1b662729a90782b99b1fb2..1fee8521e36c99e2c11dea72241482ea20a42f5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,7 @@ For users:
 - New: Module mailman can subscribe/unsubscribe to ML according to categories or type of member.
 - New: Add object_hour as substitution tag for opendocument generation.
 - New: Add option MEMBER_PAYONLINE_SENDEMAIL to send email when paypal or paybox payment is done.
+- New: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
 
 For translators:
 - Normalized sort order of all languages files with english ref file.
diff --git a/dev/skeletons/skeleton_script.php b/dev/skeletons/skeleton_script.php
index 9eb17bbbaaffc48eb6369a55cdcfb37baf60a7d6..4f8eb20cb6bb4ecbb3fd02971b3985a40e2aa56e 100644
--- a/dev/skeletons/skeleton_script.php
+++ b/dev/skeletons/skeleton_script.php
@@ -31,7 +31,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 // Global variables
@@ -60,7 +60,7 @@ $user->getrights();
 print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 if (! isset($argv[1])) {	// Check parameters
     print "Usage: ".$script_file." param1 param2 ...\n";
-    exit;
+	exit(-1);
 }
 print '--- start'."\n";
 print 'Argument 1='.$argv[1]."\n";
@@ -163,5 +163,5 @@ else
 
 $db->close();	// Close $db database opened handler
 
-return $error;
-?>
+exit($error);
+?>
\ No newline at end of file
diff --git a/scripts/bank/export-bank-receipts.php b/scripts/bank/export-bank-receipts.php
index 8ba7f665f604155c601a41877a86a61d0ee06c4f..18aa26b824691d6bfa89d1ceef6ae9700800b174 100755
--- a/scripts/bank/export-bank-receipts.php
+++ b/scripts/bank/export-bank-receipts.php
@@ -30,7 +30,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
 	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-	exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -62,8 +62,8 @@ $error=0;
 print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 
 if (! isset($argv[3]) || ! $argv[3]) {
-	print "Usage: $script_file bank_ref bank_receipt_number (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
-	exit;
+	print "Usage: ".$script_file." bank_ref bank_receipt_number (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
+	exit(-1);
 }
 $bankref=$argv[1];
 $num=$argv[2];
@@ -120,7 +120,7 @@ $result=$acct->fetch('',$bankref);
 if ($result <= 0)
 {
 	print "Failed to find bank account with ref ".$bankref.".\n";
-	exit;
+	exit(-1);
 }
 else
 {
@@ -135,7 +135,7 @@ $classname = "Export".$model;
 if (! dol_is_file($dir.$file))
 {
 	print "No driver to export with format ".$model."\n";
-	exit;
+	exit(-1);
 }
 require_once $dir.$file;
 $objmodel = new $classname($db);
@@ -247,7 +247,7 @@ if ($resql)
 			else
 			{
 				dol_print_error($db);
-				exit;
+				exit(-1);
 			}
 
 			$total = $balancebefore[$objp->num_releve];
@@ -439,5 +439,5 @@ else
 
 $db->close();
 
-return $ret;
+exit($ret);
 ?>
\ No newline at end of file
diff --git a/scripts/company/export-contacts-xls-example.php b/scripts/company/export-contacts-xls-example.php
index e3b4830f1800a743f8ab431d12542562ff0e56c5..5e7b6404994aa70b0eeaa0e7247fbac9a023b851 100644
--- a/scripts/company/export-contacts-xls-example.php
+++ b/scripts/company/export-contacts-xls-example.php
@@ -31,12 +31,12 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
 	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-	exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
 	print "Usage: $script_file now\n";
-	exit;
+	exit(-1);
 }
 $now=$argv[1];
 
@@ -120,4 +120,5 @@ $objWriter->save($fname);
 
 print 'File '.$fname.' was generated.'."\n";
 
+exit(0);
 ?>
diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php
index 26228df1ad8a9225062520d17392798b3f96696b..edede8d3ba214320d412bb04fe262e2aff8d0e21 100644
--- a/scripts/company/sync_contacts_dolibarr2ldap.php
+++ b/scripts/company/sync_contacts_dolibarr2ldap.php
@@ -31,12 +31,12 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
     print "Usage: $script_file now\n";
-    exit;
+	exit(-1);
 }
 $now=$argv[1];
 
@@ -87,7 +87,7 @@ $input = trim(fgets(STDIN));
 if (! $conf->global->LDAP_CONTACT_ACTIVE)
 {
 	print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
-	exit 1;
+	exit(-1);
 }
 */
 
@@ -147,5 +147,5 @@ else
 	dol_print_error($db);
 }
 
-return $error;
+exit($error);
 ?>
diff --git a/scripts/contracts/email_expire_services_to_customers.php b/scripts/contracts/email_expire_services_to_customers.php
index d60d5a86a5a0f66077e423b4e93fac9842215203..b503c0eaca281a549f2660ed174eb05d65a364a9 100755
--- a/scripts/contracts/email_expire_services_to_customers.php
+++ b/scripts/contracts/email_expire_services_to_customers.php
@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
 $sapi_type = php_sapi_name();
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
 	print "Send an email to customers to remind all all contracts services to expire.\n";
 	print "If you choose 'test' mode, no emails are sent.\n";
 	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
-	exit;
+	exit(-1);
 }
 $mode=$argv[1];
 
@@ -157,11 +157,15 @@ if ($resql)
     {
         print "No unpaid invoices found\n";
     }
+
+    exit(0);
 }
 else
 {
     dol_print_error($db);
     dol_syslog("email_expire_services_to_customers.php: Error");
+
+    exit(-1);
 }
 
 
@@ -269,5 +273,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
     }
 }
 
-
-?>
+?>
\ No newline at end of file
diff --git a/scripts/contracts/email_expire_services_to_representatives.php b/scripts/contracts/email_expire_services_to_representatives.php
index e570145815295e11b316042d0dd75ec1d5171b25..1a352f138aa8cade250494ee0722b740c6a9366b 100755
--- a/scripts/contracts/email_expire_services_to_representatives.php
+++ b/scripts/contracts/email_expire_services_to_representatives.php
@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
 $sapi_type = php_sapi_name();
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
 	print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
 	print "If you choose 'test' mode, no emails are sent.\n";
 	print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
-	exit;
+	exit(-1);
 }
 $mode=$argv[1];
 
@@ -154,14 +154,18 @@ if ($resql)
         }
     }
     else
-    {
+	{
         print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
     }
+
+    exit(0);
 }
 else
 {
     dol_print_error($db);
     dol_syslog("email_expire_services_to_representatives.php: Error");
+
+    exit(-1);
 }
 
 
@@ -268,5 +272,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
     }
 }
 
-
-?>
+?>
\ No newline at end of file
diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php
index 63836a979f46196c8ea960ae267f2dca3055e314..3cdf74936635f2cab1ae12fcc20bf6c93f3eedb3 100755
--- a/scripts/cron/cron_run_jobs.php
+++ b/scripts/cron/cron_run_jobs.php
@@ -1,7 +1,8 @@
 #!/usr/bin/php
 <?php
-/* Copyright (C) 2012      Nicolas Villa aka Boyquotes http://informetic.fr
- * Copyright (C) 2013      Florian Henry <forian.henry@open-cocnept.pro
+/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
+ * Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
+ * Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,18 +39,18 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
 	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-	exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
 	print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
-	exit;
+	exit(-1);
 }
 $key=$argv[1];
 
 if (! isset($argv[2]) || ! $argv[2]) {
 	print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
-	exit;
+	exit(-1);
 } else {
 	$userlogin=$argv[2];
 }
@@ -75,7 +76,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 if ($key != $conf->global->CRON_KEY)
 {
 	print "Error: securitykey is wrong\n";
-	exit;
+	exit(-1);
 }
 
 // Check user login
@@ -85,7 +86,7 @@ if ($result < 0)
 {
 	echo "User Error: ".$user->error;
 	dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
-	exit;
+	exit(-1);
 }
 else
 {
@@ -93,7 +94,7 @@ else
 	{
 		echo " User user login: ".$userlogin." do not exists";
 		dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR);
-		exit;
+		exit(-1);
 	}
 }
 
@@ -116,7 +117,7 @@ if ($result<0)
 {
 	echo "Error: ".$object->error;
 	dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
-	exit;
+	exit(-1);
 }
 
 // current date
@@ -135,14 +136,14 @@ if(is_array($object->lines) && (count($object->lines)>0))
 				if ($result<0) {
 					echo "Error:".$cronjob->error;
 					dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
-					exit;
+					exit(-1);
 				}
 				// execute methode
 				$result=$cronjob->run_jobs($userlogin);
 				if ($result<0) {
 					echo "Error:".$cronjob->error;
 					dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
-					exit;
+					exit(-1);
 				}
 
 					// we re-program the next execution and stores the last execution time for this job
@@ -150,7 +151,7 @@ if(is_array($object->lines) && (count($object->lines)>0))
 				if ($result<0) {
 					echo "Error:".$cronjob->error;
 					dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
-					exit;
+					exit(-1);
 				}
 
 			}
@@ -158,4 +159,6 @@ if(is_array($object->lines) && (count($object->lines)>0))
 }
 
 $db->close();
+
+exit(0);
 ?>
\ No newline at end of file
diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php
index 33b1160ef7ee88e662d437d43dedad8264ba2ebd..31cb141835cd8ab552a1564567495d7379510639 100755
--- a/scripts/emailings/mailing-send.php
+++ b/scripts/emailings/mailing-send.php
@@ -32,12 +32,12 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
 	print "Usage: ".$script_file." (ID_MAILING|all)\n";
-	exit;
+	exit(-1);
 }
 $id=$argv[1];
 
diff --git a/scripts/invoices/email_unpaid_invoices_to_customers.php b/scripts/invoices/email_unpaid_invoices_to_customers.php
index a7890a091c6be1f71ee1d23982105b77951e166d..6de9c1fdba7b049d0c01a6c6d07b9f462f4f20d3 100755
--- a/scripts/invoices/email_unpaid_invoices_to_customers.php
+++ b/scripts/invoices/email_unpaid_invoices_to_customers.php
@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
 $sapi_type = php_sapi_name();
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
@@ -43,7 +43,7 @@ if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm
 	print "Send an email to customers to remind all unpaid customer invoices.\n";
 	print "If you choose 'test' mode, no emails are sent.\n";
 	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
-	exit;
+	exit(-1);
 }
 $mode=$argv[1];
 $targettype=$argv[2];
@@ -187,14 +187,18 @@ if ($resql)
         }
     }
     else
-    {
+	{
         print "No unpaid invoices found\n";
     }
+
+    exit(0);
 }
 else
 {
     dol_print_error($db);
     dol_syslog("email_unpaid_invoices_to_customers.php: Error");
+
+    exit(-1);
 }
 
 
@@ -297,5 +301,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget)
     }
 }
 
-
-?>
+?>
\ No newline at end of file
diff --git a/scripts/invoices/email_unpaid_invoices_to_representatives.php b/scripts/invoices/email_unpaid_invoices_to_representatives.php
index 7e9e235591671dbaf9b8533f22d4b4a119790a90..c2adbf50c5e9b6391cf1dd026095b4a1227e75d9 100755
--- a/scripts/invoices/email_unpaid_invoices_to_representatives.php
+++ b/scripts/invoices/email_unpaid_invoices_to_representatives.php
@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
 $sapi_type = php_sapi_name();
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
 	print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
 	print "If you choose 'test' mode, no emails are sent.\n";
 	print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
-	exit;
+	exit(-1);
 }
 $mode=$argv[1];
 
@@ -164,14 +164,18 @@ if ($resql)
         }
     }
     else
-    {
+	{
         print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
     }
+
+    exit(0);
 }
 else
 {
     dol_print_error($db);
     dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
+
+    exit(-1);
 }
 
 
@@ -272,5 +276,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
     }
 }
 
-
-?>
+?>
\ No newline at end of file
diff --git a/scripts/invoices/rebuild_merge_pdf.php b/scripts/invoices/rebuild_merge_pdf.php
index a53e8940361174c52fe81a08e3abe6df681dfa9b..eeb5407b37be044b89a6f9b9dde66911d5d2e75a 100755
--- a/scripts/invoices/rebuild_merge_pdf.php
+++ b/scripts/invoices/rebuild_merge_pdf.php
@@ -30,7 +30,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 // Include Dolibarr environment
@@ -62,7 +62,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 if (! isset($argv[1]))
 {
 	usage();
-	exit;
+	exit(-1);
 }
 
 $diroutputpdf=$conf->facture->dir_output . '/temp';
@@ -125,7 +125,7 @@ foreach ($argv as $key => $value)
 		if (empty($paymentdateafter) || empty($paymentdatebefore))
 		{
 			print 'Error: Bad date format'."\n";
-			exit;
+			exit(-1);
 		}
 		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day')." and ".dol_print_date($paymentdatebefore,'day').".\n";
 	}
@@ -151,7 +151,7 @@ foreach ($argv as $key => $value)
 		if ($result <= 0)
 		{
 			print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
-			exit;
+			exit(-1);
 		}
 		$paymentonbankid=$bankaccount->id;
 		print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
@@ -185,7 +185,7 @@ foreach ($argv as $key => $value)
 	if (! $found && preg_match('/filter=/i',$value))
 	{
 		usage();
-		exit;
+		exit(-1);
 	}
 }
 
@@ -193,18 +193,18 @@ foreach ($argv as $key => $value)
 if (empty($option) && count($filter) <= 0)
 {
 	usage();
-	exit;
+	exit(-1);
 }
 // Check if there is no uncompatible choice
 if (in_array('payments',$filter) && in_array('nopayment',$filter))
 {
 	usage();
-	exit;
+	exit(-1);
 }
 if (in_array('bank',$filter) && in_array('nopayment',$filter))
 {
 	usage();
-	exit;
+	exit(-1);
 }
 
 
@@ -229,7 +229,7 @@ else
 
 $db->close();
 
-return $error;
+exit($error);
 
 
 
diff --git a/scripts/members/sync_members_dolibarr2ldap.php b/scripts/members/sync_members_dolibarr2ldap.php
index 476837aa309c23150a74b1e00a13247855a6cfca..31df696aedf4723cc018c9b1be539b2daa804cd5 100755
--- a/scripts/members/sync_members_dolibarr2ldap.php
+++ b/scripts/members/sync_members_dolibarr2ldap.php
@@ -31,7 +31,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -55,7 +55,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 
 if (! isset($argv[1]) || ! $argv[1]) {
     print "Usage: $script_file now\n";
-    exit;
+	exit(-1);
 }
 $now=$argv[1];
 
@@ -88,7 +88,7 @@ $input = trim(fgets(STDIN));
 if (! $conf->global->LDAP_MEMBER_ACTIVE)
 {
 	print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
-	exit 1;
+	exit(-1);
 }
 */
 
@@ -115,13 +115,13 @@ if ($resql)
 		if ($result < 0)
 		{
 			dol_print_error($db,$member->error);
-			exit;
+			exit(-1);
 		}
 		$result=$member->fetch_subscriptions();
 		if ($result < 0)
 		{
 			dol_print_error($db,$member->error);
-			exit;
+			exit(-1);
 		}
 
 		print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs);
@@ -158,5 +158,5 @@ else
 	dol_print_error($db);
 }
 
-return $error;
+exit($error);
 ?>
diff --git a/scripts/members/sync_members_ldap2dolibarr.php b/scripts/members/sync_members_ldap2dolibarr.php
index 1b4fc64457ce9724a60158d558dcb420df9552cf..52735e2a30e405eb1da55a3f6309120aeb60fdff 100755
--- a/scripts/members/sync_members_ldap2dolibarr.php
+++ b/scripts/members/sync_members_ldap2dolibarr.php
@@ -31,7 +31,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -98,7 +98,7 @@ print "***** $script_file ($version) *****\n";
 
 if (! isset($argv[2]) || ! is_numeric($argv[2])) {
     print "Usage:  $script_file (nocommitiferror|commitiferror) id_member_type [ldapserverhost]\n";
-    exit;
+	exit(-1);
 }
 $typeid=$argv[2];
 if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -128,12 +128,12 @@ print "\n";
 if (empty($conf->global->LDAP_MEMBER_DN))
 {
 	print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n";
-	exit(1);
+	exit(-1);
 }
 if ($typeid <= 0)
 {
 	print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n";
-	exit(2);
+	exit(-2);
 }
 
 
@@ -173,7 +173,7 @@ if ($resql)
 else
 {
 	dol_print_error($db);
-	exit;
+	exit(-1);
 }
 
 
@@ -326,7 +326,7 @@ else
 }
 
 
-return $error;
+exit($error);
 
 
 /**
@@ -340,4 +340,4 @@ function dolValidElement($element)
 	return (trim($element) != '');
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/scripts/user/sync_groups_dolibarr2ldap.php b/scripts/user/sync_groups_dolibarr2ldap.php
index 55a40209a9e3ea2e8da22b07447147f002139b10..5ecb9ee209745e94b8e45f9d3b91c6d87182287b 100755
--- a/scripts/user/sync_groups_dolibarr2ldap.php
+++ b/scripts/user/sync_groups_dolibarr2ldap.php
@@ -31,12 +31,12 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
-    print "Usage: $script_file now\n";
-    exit;
+    print "Usage: ".$script_file." now\n";
+	exit(-1);
 }
 $now=$argv[1];
 
@@ -60,7 +60,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
 {
 	print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
-	exit 1;
+	exit(-1);
 }
 */
 
@@ -120,5 +120,5 @@ else
 	dol_print_error($db);
 }
 
-return $error;
+exit($error);
 ?>
diff --git a/scripts/user/sync_groups_ldap2dolibarr.php b/scripts/user/sync_groups_ldap2dolibarr.php
index 0a0107917934fc4090d3e2b2ca2588b6777e20ed..ae8690e39965fbd4fdab34438152c23ae0c73f8f 100755
--- a/scripts/user/sync_groups_ldap2dolibarr.php
+++ b/scripts/user/sync_groups_ldap2dolibarr.php
@@ -32,7 +32,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -77,7 +77,7 @@ print "***** $script_file ($version) *****\n";
 if (! isset($argv[1])) {
 	//print "Usage:  $script_file (nocommitiferror|commitiferror) [id_group]\n";
 	print "Usage:  $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n";
-    exit;
+	exit(-1);
 }
 $groupid=$argv[3];
 if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -112,7 +112,7 @@ $input = trim(fgets(STDIN));
 if (empty($conf->global->LDAP_GROUP_DN))
 {
 	print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr");
-	exit(1);
+	exit(-1);
 }
 
 
@@ -242,7 +242,7 @@ else
 }
 
 
-return $error;
+exit($error);
 
 
 /**
@@ -256,4 +256,4 @@ function dolValidElement($element)
 	return (trim($element) != '');
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/scripts/user/sync_users_dolibarr2ldap.php b/scripts/user/sync_users_dolibarr2ldap.php
index c02a676305e3ee6ddbf4e868551297d9eff4956b..9f2dfe5d53b3997b6dde179f776ebf4c1432f76a 100755
--- a/scripts/user/sync_users_dolibarr2ldap.php
+++ b/scripts/user/sync_users_dolibarr2ldap.php
@@ -31,12 +31,12 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 if (! isset($argv[1]) || ! $argv[1]) {
     print "Usage: $script_file now\n";
-    exit;
+	exit(-1);
 }
 $now=$argv[1];
 
@@ -60,7 +60,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
 if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
 {
 	print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
-	exit 1;
+	exit(-1);
 }
 */
 
@@ -119,5 +119,5 @@ else
 	dol_print_error($db);
 }
 
-return $error;
-?>
+exit($error);
+?>
\ No newline at end of file
diff --git a/scripts/user/sync_users_ldap2dolibarr.php b/scripts/user/sync_users_ldap2dolibarr.php
index 89bc46134875b09c3f51d80d655c849be37808e3..44ead523fd61c536113fe1966152e4e39ab85714 100755
--- a/scripts/user/sync_users_ldap2dolibarr.php
+++ b/scripts/user/sync_users_ldap2dolibarr.php
@@ -31,7 +31,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
     echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-    exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -89,7 +89,7 @@ print "***** $script_file ($version) *****\n";
 if (! isset($argv[1])) {
 	//print "Usage:  $script_file (nocommitiferror|commitiferror) [id_group]\n";
 	print "Usage:  $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n";
-    exit;
+    exit(-1);
 }
 $groupid=$argv[3];
 if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -124,7 +124,7 @@ $input = trim(fgets(STDIN));
 if (empty($conf->global->LDAP_USER_DN))
 {
 	print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
-	exit(1);
+	exit(-1);
 }
 
 
@@ -158,7 +158,7 @@ if ($resql)
 else
 {
 	dol_print_error($db);
-	exit;
+	exit(-1);
 }
 
 
@@ -296,7 +296,7 @@ else
 }
 
 
-return $error;
+exit($error);
 
 
 /**
@@ -310,4 +310,4 @@ function dolValidElement($element)
 	return (trim($element) != '');
 }
 
-?>
+?>
\ No newline at end of file
diff --git a/scripts/withdrawals/build_withdrawal_file.php b/scripts/withdrawals/build_withdrawal_file.php
index 93e9239ecb7da887625362e0fca23390f42f24b6..2db617e840559205f08e85778f0d28f20cbee845 100644
--- a/scripts/withdrawals/build_withdrawal_file.php
+++ b/scripts/withdrawals/build_withdrawal_file.php
@@ -31,7 +31,7 @@ $path=dirname(__FILE__).'/';
 // Test if batch mode
 if (substr($sapi_type, 0, 3) == 'cgi') {
 	echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
-	exit;
+	exit(-1);
 }
 
 require_once($path."../../htdocs/master.inc.php");
@@ -66,7 +66,7 @@ if (! isset($argv[1])) {	// Check parameters
     print "This script check invoices with a withdrawal request and\n";
     print "then create payment and build a withdraw file.\n";
 	print "Usage: ".$script_file." simu|real\n";
-    exit;
+    exit(-1);
 }
 
 
@@ -75,4 +75,6 @@ $result=$withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE,$conf->g
 
 
 $db->close();
+
+exit(0);
 ?>
diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php
index b22dd5b1ea294b41bfbb55707578d544046f8341..f5eec24cff8d1c8bc739ffd7d33d15f53d673348 100644
--- a/test/phpunit/AllTests.php
+++ b/test/phpunit/AllTests.php
@@ -159,6 +159,9 @@ class AllTests
         require_once dirname(__FILE__).'/ImportTest.php';
         $suite->addTestSuite('ImportTest');
 
+        require_once dirname(__FILE__).'/ScriptsTest.php';
+        $suite->addTestSuite('ScriptsTest');
+
         require_once dirname(__FILE__).'/ModulesTest.php';  // At end because it's the longer
         $suite->addTestSuite('ModulesTest');
 
diff --git a/test/phpunit/ScriptsTest.php b/test/phpunit/ScriptsTest.php
new file mode 100755
index 0000000000000000000000000000000000000000..d5bda95e2b3cd0ff59c8ccf6ac3884e26d057ec5
--- /dev/null
+++ b/test/phpunit/ScriptsTest.php
@@ -0,0 +1,178 @@
+<?php
+/* Copyright (C) 2013 Laurent Destailleur  <eldy@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * or see http://www.gnu.org/
+ */
+
+/**
+ *      \file       test/phpunit/ScriptsTest.php
+ *		\ingroup    test
+ *      \brief      PHPUnit test
+ *		\remarks	To run this script as CLI:  phpunit filename.php
+ */
+
+global $conf,$user,$langs,$db;
+//define('TEST_DB_FORCE_TYPE','mysql');	// This is to force using mysql driver
+require_once 'PHPUnit/Autoload.php';
+require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
+require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php';
+require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php';
+
+if (! defined('NOREQUIREUSER'))  define('NOREQUIREUSER','1');
+if (! defined('NOREQUIREDB'))    define('NOREQUIREDB','1');
+if (! defined('NOREQUIRESOC'))   define('NOREQUIRESOC','1');
+if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
+if (! defined('NOCSRFCHECK'))    define('NOCSRFCHECK','1');
+if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
+if (! defined('NOREQUIREMENU'))  define('NOREQUIREMENU','1'); // If there is no menu to show
+if (! defined('NOREQUIREHTML'))  define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
+if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
+if (! defined("NOLOGIN"))        define("NOLOGIN",'1');       // If this page is public (can be called outside logged session)
+
+if (empty($user->id))
+{
+    print "Load permissions for admin user nb 1\n";
+    $user->fetch(1);
+    $user->getrights();
+}
+$conf->global->MAIN_DISABLE_ALL_MAILS=1;
+
+
+/**
+ * Class for PHPUnit tests
+ *
+ * @backupGlobals disabled
+ * @backupStaticAttributes enabled
+ * @remarks	backupGlobals must be disabled to have db,conf,user and lang not erased.
+ */
+class ScriptsTest extends PHPUnit_Framework_TestCase
+{
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * Constructor
+	 * We save global variables into local variables
+	 *
+	 * @return SecurityTest
+	 */
+	function __construct()
+	{
+		//$this->sharedFixture
+		global $conf,$user,$langs,$db;
+		$this->savconf=$conf;
+		$this->savuser=$user;
+		$this->savlangs=$langs;
+		$this->savdb=$db;
+
+		print __METHOD__." db->type=".$db->type." user->id=".$user->id;
+		//print " - db ".$db->db;
+		print "\n";
+	}
+
+	// Static methods
+  	public static function setUpBeforeClass()
+    {
+    	global $conf,$user,$langs,$db;
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+    	print __METHOD__."\n";
+    }
+    public static function tearDownAfterClass()
+    {
+    	global $conf,$user,$langs,$db;
+		$db->rollback();
+
+		print __METHOD__."\n";
+    }
+
+	/**
+	 * Init phpunit tests
+	 *
+	 * @return	void
+	 */
+    protected function setUp()
+    {
+    	global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		print __METHOD__."\n";
+    }
+
+	/**
+	 * End phpunit tests
+	 *
+	 * @return	void
+	 */
+    protected function tearDown()
+    {
+    	print __METHOD__."\n";
+    }
+
+    /**
+     * testBank
+     *
+     * @return string
+     */
+    public function testBank()
+    {
+    	global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$script=dirname(__FILE__).'/../../scripts/bank/export-bank-receipts.php BANKDUMMY RECEIPTDUMMY excel2007 lang=fr_FR';
+		$result=exec($script, $output, $returnvar);
+
+		print __METHOD__." result=".$result."\n";
+		print __METHOD__." output=".join("\n",$output)."\n";
+		print __METHOD__." returnvar=".$returnvar."\n";
+		$this->assertEquals($result,'Failed to find bank account with ref BANKDUMMY.');
+		$this->assertEquals($returnvar,255);
+
+        return $result;
+    }
+
+    /**
+     * testInvoices
+     *
+     * @return string
+     */
+    public function testInvoices()
+    {
+    	global $conf,$user,$langs,$db;
+    	$conf=$this->savconf;
+    	$user=$this->savuser;
+    	$langs=$this->savlangs;
+    	$db=$this->savdb;
+
+    	$script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties';
+    	$result=exec($script, $output, $returnvar);
+
+    	print __METHOD__." result=".$result."\n";
+    	print __METHOD__." output=".join("\n",$output)."\n";
+    	print __METHOD__." returnvar=".$returnvar."\n";
+    	$this->assertEquals($returnvar,0);
+
+    	return $result;
+    }
+}
+?>
\ No newline at end of file