Script to check if files exits

Hi

In live system core files are generating frequently. around 10 core files in 30 mins in root file system. which is eating my space very much
below is core file

 
 core.56539
core.78886
core.12302
core.80554
core.20147 
 

I am trying to write a script which should move this file to another path till i get the solution but it is not working.

 
 #!/bin/bash
cd /root
if [ -s *core* ]
then
    mv *cor* /tmp/scriptor
else
        echo "No core file" >>coer.log
fi
 

below is the error which i am getting

 
 ./checkcore.sh
./checkcore.sh: line 3: [: too many arguments
 

regards,
scriptor

With a rate of 1 coredumps per 3 minutes I'd rather hurry up to find the malbehaving application, seriously!

In lieu of moving the files after they show up, how about creating them in the right location immediately? Depending on the OS (which you fail to mention) there are various mechanisms to define how the core dump filename will be constucted. man core :

  • The name of the file is controlled via the sysctl(8) variable kern.corefile (FreeBSD)
  • ... the /proc/sys/kernel/core_pattern file ... can be set to define a template that ... to name core dump files (since Linux 2.6 and 2.4.21)

thx rudic fro your suggestion but it live system and not allowed to make such changes.
for problem fix team is working.

i would really appreciate i get help in moving the file to other location.
which i am trying but getting error .

The test or [ command's -s option can't cope with multiple files; *core* seems to evaluate to several file names.

suggest if there is some other way to this

As you appear to be using bash:

#!/bin/bash
shopt -s nullglob
cd /root
for cfile in *core* 
do
    mv "${cfile}" /tmp/scriptor
done
#!/bin/bash
shopt -s nullglob
cd /root
corefiles=( *core* )
if [ ${#corefiles[*]} -ge 1 ]
then
    mv *core* /tmp/scriptor
else
    echo "No core file" >>core.log
fi

The former moves one file at a time but will miss any files created after the loop starts. The latter will move all the files at once including any created between the two expansions.

Andrew

A find and mv approach :

find /root -type f -name '*core*' -size +0c -exec mv {} /my/destination \;

Regards
Peasant.

Another one with a for loop

cd /root
moved=0
for cfile in core*
do
  if [ -f "$cfile" ]
  then
    mv "$cfile" /tmp/scriptor
    moved=1
  fi
done
if [ $moved -eq 0 ]
then
  echo "No core file"
fi