K.S. Bhaskar on 9 Jan 2011 14:20:30 -0800

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Linux n00b question

On Sun, Jan 9, 2011 at 3:51 PM, JP Vossen <jp@jpsdomain.org> wrote:
>> Date: Sun, 9 Jan 2011 14:09:59 -0500
>> From: "K.S. Bhaskar"<bhaskar@bhaskars.com>
>> Subject: Re: [PLUG] Linux n00b question

[KSB] <...snip...>

>> #!/bin/bash
>> #
>> # Get password and mount /home
>> #
>> umount /home>&/tmp/umounthome_$$_`date +%Y%m%d%H%M%S`.log
>> cryptsetup remove sda2-aes>&/tmp/cryptsetupremove_$$_`date
>> +%Y%m%d%H%M%S`.log
>> cryptsetup -c aes -s 256 create sda2-aes /dev/sda2
>> 2>/tmp/cryptsetup_$$_`date +%Y%m%d%H%M%S`.log
>> fsck -a -t jfs /dev/mapper/sda2-aes | tee /tmp/fsck_$$_`date
>> +%Y%m%d%H%M%S`.log
>> mount -o relatime /dev/mapper/sda2-aes /home>&/tmp/mount_$$_`date
>> +%Y%m%d%H%M%S`.log
>> swapon /home/swap
> Oh, you're killing me!!! ÂPersonal pet peeve: running external programs
> (like date) during every line of your script unnecessarily. ÂYes, for this
> script it doesn't matter; it's still a bad habit. Â:-)
> More efficient (alignment is more personal preference):
> LOG_FILE="/tmp/umounthome_$$_`date +%Y%m%d%H%M%S`.log"
> FSCK_LOG_FILE="/tmp/fsck_$$_`date +%Y%m%d%H%M%S`.log"
> umount /home                    >& $LOG_FILE
> cryptsetup remove sda2-aes             >& $LOG_FILE
> cryptsetup -c aes -s 256 create sda2-aes /dev/sda2 2> $LOG_FILE
> fsck -a -t jfs /dev/mapper/sda2-aes       | tee $FSCK_LOG_FILE
> mount -o relatime /dev/mapper/sda2-aes /home    >& $LOG_FILE
> swapon /home/swap

[KSB] Thank you for resuscitating the voice of my conscience!  I knew
it the moment I wrote the shell script, of course, but it never seemed
worthwhile to clean up the inefficiency since that time.  Through
copying, I have propagated this inefficiency to countless systems, and
I think I'll make my first new years resolution for 2011 to clean up
my encrypted mount /home scripts...

> FYI, bash 4.2 will introduce new printf arguments to just "printf" the date.
> ÂIt's always bugged me that the shell knows what time it is (e.g. the prompt
> \D argument) but you need to use an external program to display it in a
> script. ÂAs of bash 4.2 you don't anymore. ÂI suggested that to Chet a while
> ago, but to be fair other shells have also implemented it (*cough* Paul,
> zsh, I think *cough* :), so I'm not sure what prompted him to add it to
> bash.

[KSB] Neat.  And yes, about time too.

-- Bhaskar

Windows does to computers what smoking does to humans
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug