diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh
index 6fa8aaa12c9d89213d666cdb104f7445d8455cab..40d4b6f3e5bc39156e92f48face716f4177bcd5f 100644
--- a/lustre/tests/sanity.sh
+++ b/lustre/tests/sanity.sh
@@ -4132,14 +4132,19 @@ run_test 106 "attempt exec of dir followed by chown of that dir"
 test_107() {
         CDIR=`pwd`
         cd $DIR
+
+        local file=core
+        rm -f $file
+
+        local save_pattern=$(sysctl -n kernel.core_pattern)
+        local save_uses_pid=$(sysctl -n kernel.core_uses_pid)
+        sysctl -w kernel.core_pattern=$file
+        sysctl -w kernel.core_uses_pid=0
+
         ulimit -c unlimited
         sleep 60 &
         SLEEPPID=$!
 
-        file=`sysctl -n kernel.core_pattern`
-        core_pid=`sysctl -n kernel.core_uses_pid`
-        [ $core_pid -eq 1 ] && file=$file.$SLEEPPID
-        rm -f $file
         sleep 1
 
         kill -s 11 $SLEEPPID
@@ -4151,6 +4156,8 @@ test_107() {
                 error "Fail to create core file $file"
         fi
         rm -f $file
+        sysctl -w kernel.core_pattern=$save_pattern
+        sysctl -w kernel.core_uses_pid=$save_uses_pid
         cd $CDIR
 }
 run_test 107 "Coredump on SIG"