I need to check for dpkg lock before installing apps in a script
To identify processes using files or sockets you can use fuser
command (see man fuser
for more info). In case of dpkg
, you can check for the lock as root with the following command:
fuser /var/lib/dpkg/lock
Related videos on Youtube
Noki
Primarily a software tester by trade. Though some simple dev work like automation. Love linux over the alternatives, much prefer to have a modular system that I can customise. I consider myself fairly intermediate level when it comes to linux knowledge. I know how to fix basic problems without google these days and seldom need help. I love askUbuntu, the answers I get are so clear and concise, often I even find the answer here before I ask it. Also a part-time forex trader.
Updated on September 18, 2022Comments
-
Noki over 1 year
I have a problem with a script I wrote to install a bunch of apps, basically as it loops through an array of app names to install it checks them by doing:
dpkg -l | grep -q $i
and based on the $? will either install or skip the app. Trouble is for a few items it fails due to a dpkg lock, almost the whole list works, just half a dozen fail but work if you run the script again.
Is it possible to wait for dpkg to finish before running the 'apt-get install'?
For now I've added a 'sleep 0.5' between the 2 lines and this has stopped the problem but is obviously ugly and slower.
Thanks, Noki
-
Admin about 10 yearsHow do I use this in a non-interactive script. This appears to need user input each time it queues up an application to install?
-
Admin about 10 yearsYou should better ask on the concerned answer.
-
-
jobin about 10 yearsYour answer on this question is much better/helpful IMO.
-
Radu Rădeanu about 10 years@Jobin This answer only to the current question.