0

I want to find a file with today's date as the filename in Linux.

CONFIG="/usr/local/KDS/etc/psp.conf

#result=`find -name $CONFIG.`date +%Y%m%d``
result=`find -path $CONFIG -name ".psp.conf.`date +%Y%m%d`"`

#$(date +%Y%m%d)

if [[$result -eq 0]];
then
#echo "no need to create";
cp -p /usr/local/KDS/etc/psp.conf{,.`date +%Y%m%d`}
else
#cp -p /usr/local/KDS/etc/psp.conf{,.`date +%Y%m%d`}
echo "no need to create";
fi

It does not work.

Bond
  • 16,071
  • 6
  • 30
  • 53
  • I would avoid nesting the commands like that and instead save `date +%Y%m%d` to a variable. Also the result variable will return the list of files which have been found. If you want the return code you should use `$?` – hfhc2 Jul 01 '15 at 10:00

2 Answers2

0

I tried the following:

> touch .psp.conf.`date +%Y%m%d`

To search:

> DATE=`date +%Y%m%d`
> result=`find . -name ".psp.conf.$DATE"`

After that I have

> echo "$?"
0
> echo "$result"
./.psp.conf.20150701
hfhc2
  • 4,182
  • 2
  • 27
  • 56
0

result=find -path $CONFIG -name "psp.conf.$DATE"

echo $result

if [[ $result -eq 0 ]]; then cp -p /usr/local/KDS/etc/psp.conf{,.$DATE} else echo "psp.conf.$DATE already exists." fi

Why this does not work? It didnt echo already exists even though there is file there?