Reinstalling the uninstalled packages using a bash script to make things back to normal

Well, I created a bash script which seems to work on my situation. Here I have installed a random small program to catch other error messages & saved it as “ls.shfilename.

for package in $(apt remove hello --purge 2>&1 |
 grep "warning: files list file for package '" |
 grep -Po "[^'\n ]+'" | grep -Po "[^']+");
 do apt-get install --reinstall "$package";
 done 

To solve this kinds of big time consuming problem:

dpkg: warning: files list file for package 'package-name 1' missing; assuming package has no files currently installed
....
....
dpkg: warning: files list file for package 'package-name 2000' missing; assuming package has no files currently installed

Day by day, the number of “packages” to install decreases depending upon my internet speed and whether its SSD or HDD. We all know, fast internet + SDD = Less time. But that it’s in my case. I have HDD and 500kbps download speed.

So every day I keep track of the number of the remaining packages to be installed in this way, where I read the last line number.

Now my main problem is this:

pranav@inspiron-5548L:~/Documents/command$ sudo /bin/bash ls.sh

<no output like it used to show before, but it is running though>

where I clearly don’t see what going on. No output whatsoever. Here can’t keep track of remaining packages to be reinstalled since I don’t see anything. Help me see it. It seems to be running but waiting for all packages to be re-installed and then only say something.

Answer

I clearly don’t see what going on. No output whatsoever. Here can’t keep track of remaining packages to be reinstalled since I don’t see anything. Help me see it.

This can be understood in many ways. As I understand your question, you want to debug your script, and your goal is to see what happens during script execution.

This can be achieved by invoking bash with the -x switch:

sudo /bin/bash -x ls.sh

From man bash:

-x Print commands and their arguments as they are executed.

Attribution
Source : Link , Question Author : Pranav , Answer Author : asdmin

Leave a Comment