-2

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.sh" filename.

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.

Pranav
  • 99
  • 5
  • 1
    You seem not on right way! Have a look at `/var/log/apt`, try `find /var/lib/dpkg/info -mtime -1`... – F. Hauri - Give Up GitHub Jul 27 '19 at 10:37
  • 1
    your script consumes output which was meant for human consumption, therefore it is not deterministic in nature (around git they call it 'porcelain', see https://stackoverflow.com/questions/6976473/). This is not your current problem, but it will be in a short time. To avoid falling in this trap too, you better rewrite your script use programs with deterministic (called 'plumbing' in git) output. – asdmin Jul 27 '19 at 10:42
  • @asdmin thanks, learned a new thing. – Pranav Feb 06 '21 at 07:43

2 Answers2

1

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.

asdmin
  • 2,020
  • 16
  • 28
0

By mistake, I deleted the files associated with dpkg which damanged everything. So in the end, I backup all important files and reinstalled the entire distro. Reinstalling all packages will take a huge amount of time. And not to mention, that even if do manage to reinstall all packages, there is NO guarantee things will work out the way it was.

Pranav
  • 99
  • 5