I want to make an entry in crontab that will optimize mysql database, so I am writing a script that will check if it is already present, else it will be created.
The problem I'm facing is when I check for entry it is returning many unwanted entries, to be specific all directories, files as output, present in the directory where I am executing the script.
My overall script looks like:
check=`crontab -l | grep -i "ABC"`
if [ -z "$check" ];
then
#echo " Adding opt to crontab "
crontab -l > ./tmpfile
echo "0 * * * * /bin/bash /usr/bin/mysqlcheck --all-databases -o --user=<user> --password=<pwd> 2>&1 >> ./tmpfile
crontab ./tmpfile
rm tmpfile
echo "ABC has been successfully added to crontab"
exit 1
else
echo "ABC already exists in crontab "
exit 1
fi