WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: When "One Liners" save the day  (Read 4128 times)

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
When "One Liners" save the day
« on: December 31, 2016, 05:22:34 PM »
BTW, I'm not talking about a pickup line here :p

Sometimes, things happen to onboot.lst's.    Seems like after updating deps and/or extensions, there are times we can no longer boot into a desktop.
I really needed to boot core64,  however this morning happened and my test system would no longer boot to a desktop environment.  Maybe a coincidence but I seem to recall running a system/dep update recently, so wondered if there's an issue here since the previous update was many many months ago.

So i grabbed an onboot.lst file from a similar yet working system, put it on a USBdrive and moved to the ill fated test machine.
While looking at both lists in the terminal I realist this was not going to be easy, to start with the list's were not in alphabetical order.   I think a one liner could really help here.

So, what is it we need to accomplish??
We need to compare the two onboot.lst's and update the destination lst file as required from the source, easy huh?

First compare the two files and output  any differences to terminal as we're just checking and don't know yet if there's an issue here.
Code: [Select]
for i in $(cat /mnt/sdb1/onboot_Core64.lst); do if grep -c $i /mnt/sdb1/onboot_Core64.lst; then sleep 1;  else echo "${i}_missing"; fi; done

Ok so the result of this indicated several extensions where missing.  Ok how to fix?  Easy,  we'll redirect the output of missing extensions to the suspect destination file.
We'll make a variable of path to the onboot.lst which needs updating since we may use it more than once.
Code: [Select]
dest="/mnt/sda2/tc7-x86/onboot64.lst"then:
Code: [Select]
for i in $(cat /mnt/sdb1/onboot_Core64.lst); do if grep -c $i $dest; then sleep 1;  else echo "$i" >> $dest; fi; done
success on reboot!  I admit not pretty, but I luv it when a plan comes together.

Once again a "One liner" saves the day
 ;D
« Last Edit: December 31, 2016, 05:24:32 PM by coreplayer2 »

Offline andyj

  • Hero Member
  • *****
  • Posts: 1036
Re: When "One Liners" save the day
« Reply #1 on: January 01, 2017, 08:22:18 AM »
A dual-boot system would help here too. I'm shamelessy plugging my solution to the 32/64 bit installer problem here: http://forum.tinycorelinux.net/index.php/topic,19738.msg122475.html#msg122475. Also, in the worst case scenario if you're running under VMware you can mount the virtual disk into the local file system. At least this works on Linux hosts, and I'm guessing other VM's have something similar. It's also possible to simply have multiple onboot.lst files, and create multiple entries in extlinux.conf with different command lines and have one point to a "safe" onboot.lst (another idea for TC 8  ;) ).

As for your fix, wouldn't diff and patch have done the same thing?

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: When "One Liners" save the day
« Reply #2 on: January 02, 2017, 05:28:55 AM »
Hi Andy,    My fix was not elegant and sure it could have been accomplished by many other tools.  But my point was even with a few basic tools, the one liner evolved from a search, to a fix very quickly and on one command line.  This ability of linux never ceases to amaze me.

Sure I could have booted up into one of many other boot options, but would have still resorted to some command line tools to sort through the problem.

for * in cat some file, grep another file and echo to screen   morphed into for * in cat some file, grep another file and redirect missing entries to original file

TC really offers a great set of tools with which we can accomplish almost anything, quickly.
:)