Hello, I have a regular user account that needs to run a script as a cron job. This script is to check whether or not a file exists, and if so, perform an action on that file using sudo (the file is owned by root). The problem is that the if statement fails, because the user does not have read permissions on the folder.
if [ -f $SOMEFILE ]; then
sudo cp $SOMEFILE /somewhere/else/
else
echo $SOMEFILE" not found!"
fi
The "sudo cp" command, when run on its own, works just fine. But the "if -f" condition fails because the user cannot access the folder where $SOMEFILE lives, in order to check if it exists or not.
Is there some way to use sudo in conjunction with the "if -f" condition? Or is there some other command or method I use use with sudo to check for the existence of this file?
Thank you