Hello anonymous user-0983 ,
Thanks for your query ! You might want to take a closer look at your custom script and the sequence of commands to track the process which is holding the lock.
There seems to be an issue with a race condition where something wrong with one of the command in custom script as a part of apt-get update . There might be some other applications/process using the apt. (or previous apt process is still running in the background)
You can use below command to find what process is using the apt:-
ps aux | grep '[a]pt'
(or)
ps aux | grep -i apt
(it will tell you the process name/ID which is holding the lock)
Just to debug , try to add an additional command like below in your script to find out the locks
sudo fuser /var/lib/apt/lists/lock
Do you know what that script does and how frequently it runs ?
You can try a possible workaround of adding a retry logic to the custom script temporarily to handle the error and retry after lock is gone.
Also , when it happens you might want to add a command to delete that lock file using the below command:
sudo rm -rf /var/lib/apt/lists/lock
Also in your script , check out the options/parameters passed to apt upgrade
Hope above information helps out in finding the issue !