I am creating a small bash script to automate some simple tasks to handle my docker container. One of the commands I have is to clear the logs, but this doesnt work responding with "Permission denied".
The issue with this is I am using sudo
.
if [ $CLEAR_OPT == true ]
then
DOCKER_LOG_PATH=$(docker inspect $DOCKER_ID --format='{{.LogPath}}')
sudo :> $DOCKER_LOG_PATH;
exit 0
fi
This errors out.
However this following sequence of linux commands will not error out:
sudo -s
:> /var/lib/docker/containers/path/path-json.log
I tested without using sudo -s
and it still didnt work in linux terminal.
Is there something I am missing? I thought when doing sudo
it would run the command as root user?