Index

Subject : [lug] Digest (5 messages)

From : lug-owner@lists.ncsu.[redacted]

Date : Wed, 14 Sep 2016 16:33:36 -0400


The Lug Digest
Volume 1 : Issue 393 : "text" Format

Messages in this Issue:
201609/38 : Re: Bash Scripting: If and Command Line arguments and shrinking
SD images.
Quentin Young <qlyoung@ncsu.[redacted]>
201609/39 : Re: Bash Scripting: If and Command Line arguments and shrinking SD
images.
Shawn Taylor <taylorshawn@hotmail.[redacted]>
201609/40 : Re: Bash Scripting: If and Command Line arguments and shrinking
SD images.
Quentin Young <qlyoung@ncsu.[redacted]>
201609/41 : How to Remove Thyself From the Mailing List
Quentin Young <qlyoung@ncsu.[redacted]>
201609/42 : Fwd: Free tickets for students to All Things Open 2016! Enter code NCState
Quentin Young <qlyoung@ncsu.[redacted]>

----------------------------------------------------------------------

Date: Tue, 13 Sep 2016 15:00:29 -0400
From: Quentin Young <qlyoung@ncsu.[redacted]>
To: lug@lists.ncsu.[redacted]
Subject: Re: Bash Scripting: If and Command Line arguments and shrinking
SD images.
Message-ID: <CANhSzx0RwcywnWCgGf_KZ3pXmAYgMRFKe1-MtT=kop4UBuRzNw@mail.gmail.[redacted]>

Jeffrey,

For the first one regarding bash string comparisons, I believe the correct
comparison there is

if [ "$1" == "-b" ]

and so on.

As for shrinking filesystems in images, look at resize2fs.

On Tue, Sep 13, 2016 at 11:18 AM, Jeffery Mewtamer <mewtamer@gmail.[redacted]>
wrote:

> Okay, I want to use if statements and command line arguments to
> combine some of my existing scripts that do similar things and to
> reduce cases of needing to make small edits to a script.
>
> In particular, I've got two pairs of scripts for creating and
> restoring backups, one pair that uses partimage for creating and
> restoring compressed backups of my root partition, and another pair
> that uses dd to create and restore uncompressed backups of SD cards
> for my Raspberry Pis.
>
> For the backups of my root partition, I'd like to combine the two
> scripts into one that I can give a -b or -r argument and it will
> execute the backup and restore commands respectively.
>
> Based on my Google searches, this script might look something like:
>
> #! /bin/bash
> if [$1 == -b]
> then
> <backup command>
> fi
> if [$1 == -r]
> then
> <restore-command>
> fi
>
> but I'm not sure if this is the correct syntax for comparing the first
> command line argument to a string literal.
>
> For the Raspberry Pi images, I'd like something that:
> 1. takes the device label of the card as the first command line argument.
> 2. if there is no second argument, creates an image of the designated
> card with a name like "pi-backup-[date].img in the working directory.
> 3. if the second arguement is the name of an existing image, it writes
> that image to the SD card.
>
> Could I use /dev/$1 in place of a hardcoded device label within the
> script if I just want to type sdb or sdc at the command line?
>
> How would I write the test conditions for $2 being empty or $2 being
> the name of an existing file?
>
> Also, at present, the dd command I have for creating an image leaves
> the image as the size of the SD card, which takes up a lot of space on
> my harddrive and means a lot of time would be wasted writing free
> space when writing the image to another SD card. It's possible to
> shrink an image to get rid of free space within the image, but all the
> guides I can find via Google use Gparted, which isn't scriptable, and
> since I do most things from the command line isn't an option for doing
> it manually. I could just gzip the image and it's my understanding I
> can have dd do this instead of having a separate gzip command after
> creating the image and gunzip before the write command, but it doesn't
> speed up writing images, and means I'd run out of SD card if the card
> I'm writing to is smaller than the the image was created from(I
> learned the hard way that results in an unbootable card if the image
> contains more data than the card can hold, but have no idea if it
> causes problems if the overflow is all free space). So, is there
> anything I could add in the create image if block to shrink the
> image's partitions?
>
> --
>
> Sincerely,
>
> Jeffery Wright
> President Emeritus, Nu Nu Chapter, Phi Theta Kappa.
> Former Secretary, Student Government Association, College of the Albemarle.
>



--
Quentin Young
President, LUG @ NC State


[Attachment of type text/html removed.]

------------------------------

Date: Tue, 13 Sep 2016 15:05:42 -0400
From: Shawn Taylor <taylorshawn@hotmail.[redacted]>
To: Quentin Young <qlyoung@ncsu.[redacted]>,
"lug@lists.ncsu.[redacted]"
<lug@lists.ncsu.[redacted]>
Subject: Re: Bash Scripting: If and Command Line arguments and shrinking SD
images.
Message-ID: <BLU173-W38F076938E218C326E9BCAB1FE0@phx.[redacted]>

The better way to handle the options you pass to a script is using hte built in bash features to handle them. Read through this. It highlights several options that are better than recreating this logic.
http://www.ibm.com/developerworks/library/l-bash-parameters/
There are also several special variables in BASH that you want to be familiar with, specifically in your scenarion the $# comes to mind. That is the count of all variables passed to your script.
YOu can review that here in the bash manual.
https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
Good Luck,
Shawn

From: qlyoung@ncsu.[redacted]
Date: Tue, 13 Sep 2016 15:00:29 -0400
Subject: Re: Bash Scripting: If and Command Line arguments and shrinking SD images.
To: lug@lists.ncsu.[redacted]

Jeffrey,
For the first one regarding bash string comparisons, I believe the correct comparison there is
if [ "$1" == "-b" ]
and so on.
As for shrinking filesystems in images, look at resize2fs.
On Tue, Sep 13, 2016 at 11:18 AM, Jeffery Mewtamer <mewtamer@gmail.[redacted]> wrote:
Okay, I want to use if statements and command line arguments to

combine some of my existing scripts that do similar things and to

reduce cases of needing to make small edits to a script.



In particular, I've got two pairs of scripts for creating and

restoring backups, one pair that uses partimage for creating and

restoring compressed backups of my root partition, and another pair

that uses dd to create and restore uncompressed backups of SD cards

for my Raspberry Pis.



For the backups of my root partition, I'd like to combine the two

scripts into one that I can give a -b or -r argument and it will

execute the backup and restore commands respectively.



Based on my Google searches, this script might look something like:



#! /bin/bash

if [$1 == -b]

then

<backup command>

fi

if [$1 == -r]

then

<restore-command>

fi



but I'm not sure if this is the correct syntax for comparing the first

command line argument to a string literal.



For the Raspberry Pi images, I'd like something that:

1. takes the device label of the card as the first command line argument.

2. if there is no second argument, creates an image of the designated

card with a name like "pi-backup-[date].img in the working directory.

3. if the second arguement is the name of an existing image, it writes

that image to the SD card.



Could I use /dev/$1 in place of a hardcoded device label within the

script if I just want to type sdb or sdc at the command line?



How would I write the test conditions for $2 being empty or $2 being

the name of an existing file?



Also, at present, the dd command I have for creating an image leaves

the image as the size of the SD card, which takes up a lot of space on

my harddrive and means a lot of time would be wasted writing free

space when writing the image to another SD card. It's possible to

shrink an image to get rid of free space within the image, but all the

guides I can find via Google use Gparted, which isn't scriptable, and

since I do most things from the command line isn't an option for doing

it manually. I could just gzip the image and it's my understanding I

can have dd do this instead of having a separate gzip command after

creating the image and gunzip before the write command, but it doesn't

speed up writing images, and means I'd run out of SD card if the card

I'm writing to is smaller than the the image was created from(I

learned the hard way that results in an unbootable card if the image

contains more data than the card can hold, but have no idea if it

causes problems if the overflow is all free space). So, is there

anything I could add in the create image if block to shrink the

image's partitions?



--



Sincerely,



Jeffery Wright

President Emeritus, Nu Nu Chapter, Phi Theta Kappa.

Former Secretary, Student Government Association, College of the Albemarle.



--
Quentin YoungPresident, LUG @ NC State


[Attachment of type text/html removed.]

------------------------------

Date: Tue, 13 Sep 2016 15:06:52 -0400
From: Quentin Young <qlyoung@ncsu.[redacted]>
To: lug@lists.ncsu.[redacted]
Subject: Re: Bash Scripting: If and Command Line arguments and shrinking
SD images.
Message-ID: <CANhSzx0LqVVyHpxgPzuxV8q9GqEqwQXU3R83Gs=-Kei2r4y2kA@mail.gmail.[redacted]>

If you want to check if an arg is empty or not, use

if [ -z "$1" ]

or whatever the index of the argument in question is.

You should be able to use /dev/$1 to get substitution there.

File existence, try:

if [ -e "filename" ]

Other file tests here:
http://tldp.org/LDP/abs/html/fto.html

And to elaborate on using resize2fs, my naive approach would be:

1. dd the image off the card
2. Use resize2fs to resize the filesystem

I believe gparted uses resize2fs under the hood.

On Tue, Sep 13, 2016 at 3:00 PM, Quentin Young <qlyoung@ncsu.[redacted]> wrote:

> Jeffrey,
>
> For the first one regarding bash string comparisons, I believe the correct
> comparison there is
>
> if [ "$1" == "-b" ]
>
> and so on.
>
> As for shrinking filesystems in images, look at resize2fs.
>
> On Tue, Sep 13, 2016 at 11:18 AM, Jeffery Mewtamer <mewtamer@gmail.[redacted]>
> wrote:
>
>> Okay, I want to use if statements and command line arguments to
>> combine some of my existing scripts that do similar things and to
>> reduce cases of needing to make small edits to a script.
>>
>> In particular, I've got two pairs of scripts for creating and
>> restoring backups, one pair that uses partimage for creating and
>> restoring compressed backups of my root partition, and another pair
>> that uses dd to create and restore uncompressed backups of SD cards
>> for my Raspberry Pis.
>>
>> For the backups of my root partition, I'd like to combine the two
>> scripts into one that I can give a -b or -r argument and it will
>> execute the backup and restore commands respectively.
>>
>> Based on my Google searches, this script might look something like:
>>
>> #! /bin/bash
>> if [$1 == -b]
>> then
>> <backup command>
>> fi
>> if [$1 == -r]
>> then
>> <restore-command>
>> fi
>>
>> but I'm not sure if this is the correct syntax for comparing the first
>> command line argument to a string literal.
>>
>> For the Raspberry Pi images, I'd like something that:
>> 1. takes the device label of the card as the first command line argument.
>> 2. if there is no second argument, creates an image of the designated
>> card with a name like "pi-backup-[date].img in the working directory.
>> 3. if the second arguement is the name of an existing image, it writes
>> that image to the SD card.
>>
>> Could I use /dev/$1 in place of a hardcoded device label within the
>> script if I just want to type sdb or sdc at the command line?
>>
>> How would I write the test conditions for $2 being empty or $2 being
>> the name of an existing file?
>>
>> Also, at present, the dd command I have for creating an image leaves
>> the image as the size of the SD card, which takes up a lot of space on
>> my harddrive and means a lot of time would be wasted writing free
>> space when writing the image to another SD card. It's possible to
>> shrink an image to get rid of free space within the image, but all the
>> guides I can find via Google use Gparted, which isn't scriptable, and
>> since I do most things from the command line isn't an option for doing
>> it manually. I could just gzip the image and it's my understanding I
>> can have dd do this instead of having a separate gzip command after
>> creating the image and gunzip before the write command, but it doesn't
>> speed up writing images, and means I'd run out of SD card if the card
>> I'm writing to is smaller than the the image was created from(I
>> learned the hard way that results in an unbootable card if the image
>> contains more data than the card can hold, but have no idea if it
>> causes problems if the overflow is all free space). So, is there
>> anything I could add in the create image if block to shrink the
>> image's partitions?
>>
>> --
>>
>> Sincerely,
>>
>> Jeffery Wright
>> President Emeritus, Nu Nu Chapter, Phi Theta Kappa.
>> Former Secretary, Student Government Association, College of the
>> Albemarle.
>>
>
>
>
> --
> Quentin Young
> President, LUG @ NC State
>



--
Quentin Young
President, LUG @ NC State


[Attachment of type text/html removed.]

------------------------------

Date: Tue, 13 Sep 2016 17:31:47 -0400
From: Quentin Young <qlyoung@ncsu.[redacted]>
To: lug@lists.ncsu.[redacted]
Subject: How to Remove Thyself From the Mailing List
Message-ID: <CANhSzx3GWOnjpHgG3geay9ybVm76=03579PXzB1xg6hy=Y0few@mail.gmail.[redacted]>

Hi LUG,

Yet again it's time for me to send out instructions on how to unsubscribe
yourself from the mailing list. Every semester without fail we get lots of
folks who like to subscribe to the mailing list, ignore their registration
emails, and then as soon as we start using it decide they want to
unsubscribe, but can't seem to figure out how. Invariably, they email me,
because apparently I'm the listserv administrator, and I know your user
password!

...If only.

For those of you wanting to unsubscribe:

1. Google *"ncsu list serv unsubscribe"*
2. Click the first result <http://lists.ncsu.edu/>
3. Click "subscriber interface"
4. Enter your email address
5. Enter your password
6. Choose the list you want to unsubscribe from

If anyone needs assistance with these steps, feel free to contact the NC
State Help Desk at help@ncsu.[redacted] <http://help@ncsu.[redacted].>.

I do not know your password. I cannot unsubscribe you.

--
Quentin Young
President, LUG @ NC State


[Attachment of type text/html removed.]

------------------------------

Date: Wed, 14 Sep 2016 16:33:31 -0400
From: Quentin Young <qlyoung@ncsu.[redacted]>
To: lug@lists.ncsu.[redacted]
Subject: Fwd: Free tickets for students to All Things Open 2016! Enter code NCState
Message-ID: <CANhSzx0NZfQ-5kmCOCL-v3bGLpTda4hUT7=8m8dPa3Wy4z9CJA@mail.gmail.[redacted]>

LUG,

See opportunity below.
---------- Forwarded message ----------
From: "Todd Lewis" <toddl151@gmail.[redacted]>
Date: Sep 14, 2016 4:29 PM
Subject: Free tickets for students to All Things Open 2016! Enter code
NCState
To: <kmtate2@ncsu.[redacted]>
Cc: "Ryan Hefner" <rhefner@redhat.[redacted]>, "Danny Perez-Caballero" <
danny@allthingsopen.[redacted]>, <ccchestn@ncsu.[redacted]>, <dsglasse@ncsu.[redacted]>, <
imkilgor@ncsu.[redacted]>, <qlyoung@ncsu.[redacted]>

Hi Ken. This is Todd Lewis with All Things Open. Hope you're doing well
today.

Each year we make *15 FREE tickets* available to university students at NC
State. Any interested student must enter the discount code *NCState* when
they register and the cost will be reduced to $0.

Would you forward this to CS/technology students when time permits? Any
help is much appreciated. We believe access to a world-class technology
conference like ATO is vital to the development of tomorrow's
professionals. This is part of our commitment :)

Thanks so much! *These are always gone within minutes.*

Todd

*All Things Open 2016*
Largest Open Source/Open Tech/Open Web event on the east coast
October 26 + 27
Raleigh Convention Center

Website and information: https://allthingsopen.org
To register: http://allthingsopen.org/register-now
Why Attend?
<https://allthingsopen.org/wp-content/uploads/2016/06/ATO_2016_WhyAttend.pdf>

15 FREE passes for students - first come-first served: Enter code
*NCState* when
register
Student cost (after the 15 free are gone): $49 per day/$79 for both days
(this represents a significant discount and includes all programming, lunch
+ networking, choose the "student option" when registering)
20% discount for NC State staff: *NCState20* (enter the code when you
register and price will be reduced)

*All Things Open*
All Things Open is a two-day technology conference taking place in downtown
Raleigh, NC USA on October 26 and 27. The focus is open source, open tech
and the open web in the enterprise. It is the largest open technology
event on the east coast of the United States.

More than 2,000 technologists and decision makers from all over the world
will attend and participate. In addition, more than 180 sessions and 150
speakers will be featured. Nearly every major technology company in the
U.S. will be there.


[Attachment of type text/html removed.]

------------------------------

End of [lug] Digest (5 messages)
**********