6

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

Clayton
  • 1,423
Noki
  • 932
  • How do I use this in a non-interactive script. This appears to need user input each time it queues up an application to install? – Noki May 17 '14 at 15:46
  • You should better ask on the concerned answer. – jobin May 17 '14 at 15:48

1 Answers1

12

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
Radu Rădeanu
  • 169,590