LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 04-29-2004, 12:26 AM   #1
KWTm
Member
 
Registered: Jan 2004
Distribution: Kubuntu 14.04 (Dell Linux-preinstalled laptop + 2 other laptops)
Posts: 117

Rep: Reputation: 21
Lightbulb How I Keep Track of How I Configured My Linux Box


As a Linux tinkerer, here is a technique I use to log what I've done and make notes. This applies to commands I type in the shell, especially when I'm configuring the system as root.

In my own ~/bin directory, which I've placed onto my path (put "PATH=$PATH:$HOME/bin ; export PATH" in ~/.bashrc), I have a script called "myinstall" where I type in any command that has to do with administration. Same thing for root. When I'm ready, then I type "myinstall" as a command, and it runs my command. When I have another command, again I edit the myinstall file (commenting out the previous command) and run myinstall again.

For example, in the beginning, myinstall might look like this:

-----( start )
#!/bin/sh

urpmi.addmedia thacs.rpms http://rpm.nyvalls.se/9.2/RPMS with hdlist.cz
-----( end )

Then when I'm ready, instead of typing "urpmi.addmedia ... bla bla bla" (an example command for this illustration --never mind what it does) at the command line, I just type "myinstall".

Then I'm ready to do the next step, so now myinstall is edited to look like this:

-----( start )
#!/bin/sh

#urpmi.addmedia thacs.rpms http://rpm.nyvalls.se/9.2/RPMS with hdlist.cz
urpmi --noclean freevo

-----( end )

Then when I'm ready, I type "myinstall" again.

What are the advantages of this? There are many:

- I can edit my command. I might want to do some cutting and pasting to enter that big long "urpmi.addmedia ..." command. Sure, you can do some command-line editing, but it's much easier to use a text editor (KWrite in KDE, or nano in console) and it's more flexible.
- If I make a mistake, I can easily edit and re-execute "myinstall". (Those of you thinking, "but up-arrow recalls the previous command line in the shell" aren't thinking of multi-line commands.)
- I have a record of what I did. In the future, if I can't remember that web site I had to type in as part of the command, or I forget whether the correct command was "urpmi -no-clean" or "urpmi --noclean", it's all there for me to see.
- I can comment on what I'm doing! You won't believe how valuable this is. You can insert lines that say, "# Oops, that didn't work let's try it this way instead:", and when reviewing your notes in the future, you can avoid the same mistakes. This is especially when you're debugging some configuration.
- I can easily re-execute the commands if I'm re-installing. In fact, this was the original reason I started doing this: I have two computers, and I didn't want to go through the hassle of figuring everything out for a second time on the second computer. On the other hand, the partitioning and configuration of the two computers is slightly different, so I couldn't just copy all the config files directly. With the above method, I can edit the myinstall file and do what's needed, skipping over the unneeded parts.

At first, each time I ran "myinstall", I then commented out the line(s) so it wouldn't execute again the next time. This got to be tedious, like this:

-----( start )
#!/bin/sh

#install program1 # Okay, done that, so we'll comment this line out.
#install program2 # Okay, done that, so we'll comment this line out.
#install program3 # Okay, done that, so we'll comment this line out.
#install program4 # Okay, done that, so we'll comment this line out.
#install program5 # Okay, done that, so we'll comment this line out.
#install program6 # Okay, done that, so we'll comment this line out.

install program7 # This is what we will do next

-----( end )


Not only did I have to comment out each line, which was tedious (especially if I ran several lines at a time), but if I wanted to redo what I had done before (say, install programs 3 to 6 over again), I'd have to uncomment each line. Then I figured out an easy way to "comment out" huge chunks of lines at a time:


-----( start )
#!/bin/sh

if [ 1 = 2 ] ; then
# This "if/then" is never true, so anything within
# this group is never executed
# --so it's as if we commented it out!

install program1 # Okay, done that
install program2 # Okay, done that
install program3 # Okay, done that
install program4 # Okay, done that
install program5 # Okay, done that
install program6 # Okay, done that


fi # "fi" is end of the "if" structure, so
# anything following this *will* be executed

install program7 # This is what we will do next

-----( end )


And so if I need to install programs 3 to 7 over again, I just move the "fi" line up before "install program3" and it will re-execute.

(For those of you using KWrite with KDE, Ctrl-Shift-B will switch to block mode so you can delete those hash marks "#" in a column without affecting the rest of the lines.)

Anyway, thought that might help. In tinkering with Linux, I've installed a dozen distros on a dozen disk partitions, and wish I had thought of this earlier.
 
Old 04-29-2004, 10:24 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Re: How I Keep Track of How I Configured My Linux Box

That's some nifty and ingenious stuff. Just thought I'd mention, though, that modern shells have a lot of nice features along these lines. (I may be misunderstanding some of the subtleties, but it seems like a lot of things can be done conventionally.)

Quote:
Originally posted by KWTm
...What are the advantages of this? There are many:

- I can edit my command. I might want to do some cutting and pasting to enter that big long "urpmi.addmedia ..." command. Sure, you can do some command-line editing, but it's much easier to use a text editor (KWrite in KDE, or nano in console) and it's more flexible.


Actually, if you look into command line editing, it's quite flexible. Word subsitution, reusing parts of the line, etc.

- If I make a mistake, I can easily edit and re-execute "myinstall". (Those of you thinking, "but up-arrow recalls the previous command line in the shell" aren't thinking of multi-line commands.)

Multi-line commands are usually resequenced as a semi-colon separated one liner, but it's still there. Zsh handles multi-lines as multi-lines.

Code:
~
j@slackmagick zsh 4.2.0 04/29/04 11:16:18 
365 >>  for f in .; do 
for> ls $f
for> done
af  bin  doc  foo_term_keys.txt  gf  html  sbin  src  tmp  txt  user.2.log  var

[arrow up]

~
j@slackmagick zsh 4.2.0 04/29/04 11:16:37 
366 >>  for f in .; do
ls $f
done
- I have a record of what I did. In the future, if I can't remember that web site I had to type in as part of the command, or I forget whether the correct command was "urpmi -no-clean" or "urpmi --noclean", it's all there for me to see.
- I can comment on what I'm doing! You won't believe how valuable this is. You can insert lines that say, "# Oops, that didn't work let's try it this way instead:", and when reviewing your notes in the future, you can avoid the same mistakes. This is especially when you're debugging some configuration.


You can comment on the command line:

Code:
~
j@slackmagick zsh 4.2.0 04/29/04 11:16:37 
366 >>  ls # commenting my history
af  bin  doc  foo_term_keys.txt  gf  html  sbin  src  tmp  txt  user.2.log  var

~
j@slackmagick zsh 4.2.0 04/29/04 11:17:42 
367 >>  tail -n2 ~/.zsh/.zhistory
: 1083251862:0; ls # commenting my history
: 1083251872:0;tail -n2 ~/.zsh/.zhistory
Zsh history has extra timestamps and whatnot, but the same principle works with bash.

- I can easily re-execute the commands if I'm re-installing...Then I figured out an easy way to "comment out" huge chunks of lines at a time:...[if control stuff]...

And so if I need to install programs 3 to 7 over again, I just move the "fi" line up before "install program3" and it will re-execute.
That's convenient. Can't think of a way to manage that directly with line editing and history. Just thought I'd add a mention of some nice shell tricks - whichever suits. I do a lot of end-runs around the shell, myself, at times, because I like doing stuff my way. More people should post more cool shell tips and methods. CLI-phobic people have no idea what fun they're missing.
 
Old 04-29-2004, 10:37 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
More people should post more cool shell tips and methods. CLI-phobic people have no idea what fun they're missing.
Forums > Linux - General > Tricks and hints?
 
Old 04-29-2004, 10:51 AM   #4
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Yeah, like that.

I actually posted on that thread. Wonder what happened to my subscription? (Thanks for posting it - I'll resubscribe.)

Not saying people didn't, but more is better.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubleshooting Slow Transfer Speed Between Linux Box and Windows Box timswim78 Linux - General 1 10-23-2005 11:45 AM
Linux box with eth0 to cable modem and eth1 to Windows box videojeff Linux - Networking 23 03-03-2005 07:58 PM
Password Message Box when accessing linux box from Window Machine mikeccs Linux - Networking 1 08-04-2004 05:47 AM
Linux box calling a batch script on a windows box to run? Is it possible? joelhop Programming 8 05-17-2004 04:49 PM
Finally Gotten Linux Configured! Cruxus LinuxQuestions.org Member Intro 0 08-10-2003 12:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 05:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration