Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I use technology in order to hate it more properly. -- Nam June Paik


devel / comp.unix.shell / Wrote a bash script to create and add a swapfile

SubjectAuthor
* Wrote a bash script to create and add a swapfileCecil Westerhof
+* Re: Wrote a bash script to create and add a swapfileBen Bacarisse
|`* Meta re: the state of the economy and various other topics (Was: Wrote a bash scKenny McCormack
| +* Re: Meta re: the state of the economy and various other topicsAragorn
| |`- Re: Meta re: the state of the economy and various other topicsCecil Westerhof
| `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|  `* Re: Meta re: the state of the economy and various other topicsEd Morton
|   `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|    `* Re: Meta re: the state of the economy and various other topicsEd Morton
|     `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|      +- Re: Meta re: the state of the economy and various other topicsKenny McCormack
|      `* Re: Meta re: the state of the economy and various other topicsEd Morton
|       `* Re: Meta re: the state of the economy and various other topicsCecil Westerhof
|        `* Re: Meta re: the state of the economy and various other topicsEd Morton
|         `- Re: Meta re: the state of the economy and various other topicsPercival John Hackworth
+* Re: Wrote a bash script to create and add a swapfileAuric__
|`* cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfCecil Westerhof
| `* Re: cross-post, or multi-post Was: Re: Wrote a bash script toAragorn
|  `* Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a sCecil Westerhof
|   +* Re: cross-post, or multi-post Was: Re: Wrote a bash script to createDavid W. Hodgins
|   |`- Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a sAuric__
|   `- Re: cross-post, or multi-postHelmut Waitzmann
+* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|+* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||+* Re: Wrote a bash script to create and add a swapfileEd Morton
|||+* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
||||+* Re: Wrote a bash script to create and add a swapfileKenny McCormack
|||||+- Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|||||`- Re: Wrote a bash script to create and add a swapfileGeoff Clare
||||`* Re: Wrote a bash script to create and add a swapfileAnssi Saari
|||| `- Re: Wrote a bash script to create and add a swapfileLew Pitcher
|||`- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||`* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|| `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||  `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
||   `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
||    `- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
|`* Re: Wrote a bash script to create and add a swapfileEd Morton
| +- Re: Wrote a bash script to create and add a swapfileKenny McCormack
| +* Re: Wrote a bash script to create and add a swapfileAragorn
| |+- Re: Wrote a bash script to create and add a swapfileEd Morton
| |`* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
| | `* Re: Wrote a bash script to create and add a swapfileJanis Papanagnou
| |  `- Re: Wrote a bash script to create and add a swapfileCecil Westerhof
| `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|  `* Re: Wrote a bash script to create and add a swapfileEd Morton
|   `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
|    `- Re: Wrote a bash script to create and add a swapfileEd Morton
`* Re: Wrote a bash script to create and add a swapfileKaz Kylheku
 `* Re: Wrote a bash script to create and add a swapfileCecil Westerhof
  `* Re: Wrote a bash script to create and add a swapfilegerg
   `- Re: Wrote a bash script to create and add a swapfileJanis Papanagnou

Pages:123
Wrote a bash script to create and add a swapfile

<874jyccqbs.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5633&group=comp.unix.shell#5633

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 14:42:31 +0200
Organization: Decebal Computing
Lines: 11
Message-ID: <874jyccqbs.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="72986"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SLs6++hj/akXgIDVymVj1NMggo7HSlz4="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:tsfL87rXy6mwcqLIrZK+ghELOLk=
sha1:OFj041PSL/zqnGozjMw+TuJZ5WQ=
 by: Cecil Westerhof - Tue, 16 Aug 2022 12:42 UTC

For people who know Bash, but like to learn write (better) scripts I
wrote an article about a script I wrote to create and add a swapfile:
https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof

You can get the script here:
https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<87mtc45okr.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5634&group=comp.unix.shell#5634

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 14:02:12 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <87mtc45okr.fsf@bsb.me.uk>
References: <874jyccqbs.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="26b655d52b699ab945ead8c3f796c857";
logging-data="72187"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pFHSqlBY8NrnbLaTTFoMaSGJN2cyekOc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:5crvaTBOwoH87VTo4dAS8fu46kc=
sha1:yVTRN+7k9eJ9qbZ9izUoQepCs6E=
X-BSB-Auth: 1.2e7d216c449b846775c5.20220816140212BST.87mtc45okr.fsf@bsb.me.uk
 by: Ben Bacarisse - Tue, 16 Aug 2022 13:02 UTC

Cecil Westerhof <Cecil@decebal.nl> writes:

> For people who know Bash, but like to learn write (better) scripts I
> wrote an article about a script I wrote to create and add a swapfile:
> https://...

Why post a link? We discuss shell programming here, not there! Post
the content here.

Posting links and no content is what spammers do and I'm sure you don't
want to be taken for a spammer.

--
Ben.

Meta re: the state of the economy and various other topics (Was: Wrote a bash script to create and add a swapfile)

<tdg8tb$84fr$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5635&group=comp.unix.shell#5635

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Meta re: the state of the economy and various other topics (Was: Wrote a bash script to create and add a swapfile)
Date: Tue, 16 Aug 2022 14:17:15 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tdg8tb$84fr$1@news.xmission.com>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
Injection-Date: Tue, 16 Aug 2022 14:17:15 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="266747"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Tue, 16 Aug 2022 14:17 UTC

In article <87mtc45okr.fsf@bsb.me.uk>,
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>Cecil Westerhof <Cecil@decebal.nl> writes:
>
>> For people who know Bash, but like to learn write (better) scripts I
>> wrote an article about a script I wrote to create and add a swapfile:
>> https://...
>
>Why post a link? We discuss shell programming here, not there! Post
>the content here.
>
>Posting links and no content is what spammers do and I'm sure you don't
>want to be taken for a spammer.

Let me first say that I 100% agree with you in principle. That in the
model of classic Usenet, sure, OP could have just posted his script in the
item. However, let me play devil's advocate for the rest of this post:

1) We live in a "clicks equals money" world, and it is quite possible that
OP was looking to make a little cash from having you follow his links.
Given that we live in a world where the elites are crushing the middle
class, and everybody is encouraged to have a "side hustle" or two, I can't
say this is necessarily a bad thing (on OP's part).

2) I'm not sure that OP is interested in the usual "human compiler"
treatment that we usually deal in here on Usenet. That is, where eager
folks like you and me go through his script line by line, like a compiler
would, and make derogatory comments where we can. Instead, I think he was
just putting it out there as something you may (or may not) enjoy reading.
I really didn't get the impression that he wanted or was seeking any human
compilers.

Note, BTW, that I did go and read his post (on linked in) and if I *WAS* so
inclined, I could make some (in fact, quite a few) human compiler comments,
but I do not intend on doing so.

--
"The most unsettling aspect of my atheism for Christians is
when they realize that their Bible has no power to make me
wince. They are used to using it like a cattle prod to get
people to cower into compliance." - Author unknown

Re: Wrote a bash script to create and add a swapfile

<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5636&group=comp.unix.shell#5636

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: not.my.r...@email.address (Auric__)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 15:26:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
References: <874jyccqbs.fsf@munus.decebal.nl>
Injection-Date: Tue, 16 Aug 2022 15:26:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="6a3f17ab46eb87a09526e5ec8722b53a";
logging-data="100731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cIHZUmgRjf6fU8xjJEbTo"
User-Agent: Xnews/2009.05.01
Cancel-Lock: sha1:oUROF2wZyMB++S99D72QPnoO768=
X-Face: +,&^!i3LPqz7/qfxgF[JJqAP^>bTVLZ-zj})PmI{auZ']fwMM4mh`$]b0sacD4p@R[yU'Mf=.T}|aW6^#_lm6U|e|/#d:nfRn29,GBLvX=ygRH(?h.=KFfJ\INamt#H|)k@,x[ko$(d~iAo'<1XzB@%];
 by: Auric__ - Tue, 16 Aug 2022 15:26 UTC

Cecil Westerhof wrote:

> For people who know Bash, but like to learn write (better) scripts I
> wrote an article about a script I wrote to create and add a swapfile:
> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>
> You can get the script here:
> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwap
> File.sh

In the future, please don't multi-post. Crosspost instead. (Also found in
alt.os.linux.)

--
Time and space are illusions.

Re: Meta re: the state of the economy and various other topics (Was: Wrote a bash script to create and add a swapfile)

<20220816193718.2fc987e3@nx-74205>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5638&group=comp.unix.shell#5638

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: thoron...@telenet.be (Aragorn)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
(Was: Wrote a bash script to create and add a swapfile)
Date: Tue, 16 Aug 2022 19:37:18 +0200
Organization: A noiseless patient Strider
Lines: 66
Message-ID: <20220816193718.2fc987e3@nx-74205>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: reader01.eternal-september.org; posting-host="3a2e7482b3f77585ddf9c89bfb4669cb";
logging-data="45480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RuqTGj8VHOkqlfCmWQgeM"
Cancel-Lock: sha1:04yAWS5hRzPDFUJvPlckCtoFd4E=
X-Newsreader: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu)
 by: Aragorn - Tue, 16 Aug 2022 17:37 UTC

On 16.08.2022 at 14:17, Kenny McCormack scribbled:

> In article <87mtc45okr.fsf@bsb.me.uk>,
> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> >Cecil Westerhof <Cecil@decebal.nl> writes:
> >
> >> For people who know Bash, but like to learn write (better) scripts
> >> I wrote an article about a script I wrote to create and add a
> >> swapfile: https://...
> >
> >Why post a link? We discuss shell programming here, not there! Post
> >the content here.
> >
> >Posting links and no content is what spammers do and I'm sure you
> >don't want to be taken for a spammer.
>
> Let me first say that I 100% agree with you in principle. That in the
> model of classic Usenet, sure, OP could have just posted his script
> in the item.

So far, so good, and I agree with you on that.

> However, let me play devil's advocate for the rest of this post:
>
> 1) We live in a "clicks equals money" world, and it is quite possible
> that OP was looking to make a little cash from having you follow his
> links. Given that we live in a world where the elites are crushing
> the middle class, and everybody is encouraged to have a "side hustle"
> or two, I can't say this is necessarily a bad thing (on OP's part).

I have interacted with Cecil in person off of Usenet several years ago
regarding a presentation he was creating on account of systemd — he
himself may not remember that anymore, but I happen to have an eidetic
memory.

Cecil is not the kind of person you are describing above. He is
someone who's eager to contribute to the FLOSS community, he
absolutely loves scripting in GNU bash, and he takes pride in his work.

His thread was also posted to at least one other newsgroup I'm
monitoring — perhaps he forgot to cross-post and so ended up
multi-posting — and it was intended as a mere announcement.

> 2) I'm not sure that OP is interested in the usual "human compiler"
> treatment that we usually deal in here on Usenet. That is, where
> eager folks like you and me go through his script line by line, like
> a compiler would, and make derogatory comments where we can.
> Instead, I think he was just putting it out there as something you
> may (or may not) enjoy reading. I really didn't get the impression
> that he wanted or was seeking any human compilers.

As I said, it was a mere announcement.

> Note, BTW, that I did go and read his post (on linked in) and if I
> *WAS* so inclined, I could make some (in fact, quite a few) human
> compiler comments, but I do not intend on doing so.

From my prior interactions with Cecil, I know that he always welcomes
all constructive commentary. But he wasn't fishing for it, and knowing
him, his code is probably sufficiently good already, even if perhaps
not perfect.

--
With respect,
= Aragorn

Re: Wrote a bash script to create and add a swapfile

<87r11g9jjs.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5639&group=comp.unix.shell#5639

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 19:37:11 +0200
Organization: Decebal Computing
Lines: 66
Message-ID: <87r11g9jjs.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="134818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tEg46uLqaSWyUYWVKMBq6wmtg1aXM8j4="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:duQvwz0VwNSFi3kzglYUh+54/Ss=
sha1:zzLPYxJtMXF0k/zy1Kgulj0++9M=
 by: Cecil Westerhof - Tue, 16 Aug 2022 17:37 UTC

Cecil Westerhof <Cecil@decebal.nl> writes:

> For people who know Bash, but like to learn write (better) scripts I
> wrote an article about a script I wrote to create and add a swapfile:
> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>
> You can get the script here:
> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh

The script my post explains.

#!/usr/bin/env bash

set -o errexit
set -o nounset

function getFreeGB {
df -BG $(dirname $1) | \
tail -n 1 | \
awk '{print substr($4, 1, length($4) - 1)}'
}

function giveError {
echo $1
exit 1
}

declare -r _scriptName=$(basename ${0})
if [[ $(id --user) -ne 0 ]] ; then
giveError "${_scriptName} should be run as root"
fi
if [[ $# -ne 2 ]] ; then
giveError "ERROR: ${_scriptName} SWAPFILE GB"
fi
declare -r _swapFile=$1
declare -ir _gb=$2

if [[ -e ${_swapFile} ]] ; then
giveError "${_swapFile} already exists"
fi
declare -ir _gbFree=$(getFreeGB ${_swapFile})
# Make sure swapfile is less as a quarter of free space
if [[ ${_gbFree} -le $(($_gb * 4)) ]] ; then
giveError "Not enough space for swap file ($_gb, ${_gbFree})"
fi
echo Current Swap:
swapon
echo
date "+%T: Creating ${_swapFile}"
dd if=/dev/zero of=${_swapFile} bs=1024 count=$(($_gb * 1024 ** 2))
echo
chmod 600 ${_swapFile}
mkswap ${_swapFile}
swapon ${_swapFile}
echo New Swap:
swapon

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<87zgg49juu.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5640&group=comp.unix.shell#5640

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Tue, 16 Aug 2022 19:30:33 +0200
Organization: Decebal Computing
Lines: 59
Message-ID: <87zgg49juu.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="134818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JfAW3kqhTJPoloNdAtc88VPSk3S8Rhpc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:P7oxCG6Aib7zXQbovYxhLB2zPWo=
sha1:FIdui85gIW74omxS+UJSbFr90Ws=
 by: Cecil Westerhof - Tue, 16 Aug 2022 17:30 UTC

gazelle@shell.xmission.com (Kenny McCormack) writes:

> In article <87mtc45okr.fsf@bsb.me.uk>,
> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>>Cecil Westerhof <Cecil@decebal.nl> writes:
>>
>>> For people who know Bash, but like to learn write (better) scripts I
>>> wrote an article about a script I wrote to create and add a swapfile:
>>> https://...
>>
>>Why post a link? We discuss shell programming here, not there! Post
>>the content here.
>>
>>Posting links and no content is what spammers do and I'm sure you don't
>>want to be taken for a spammer.
>
> Let me first say that I 100% agree with you in principle. That in the
> model of classic Usenet, sure, OP could have just posted his script in the
> item. However, let me play devil's advocate for the rest of this post:
>
> 1) We live in a "clicks equals money" world, and it is quite possible that
> OP was looking to make a little cash from having you follow his links.
> Given that we live in a world where the elites are crushing the middle
> class, and everybody is encouraged to have a "side hustle" or two, I can't
> say this is necessarily a bad thing (on OP's part).

No it is not about clicks. ;-)
I created a bash group on LinkedIn and there was a question about how
to learn to program in bash. So I wrote a script and an article
explaining the script with hopefully interesting tips for people how
to create their own scripts.

I just thought/hoped it could be interesting for people using this
newsgroup.

> 2) I'm not sure that OP is interested in the usual "human compiler"
> treatment that we usually deal in here on Usenet. That is, where eager
> folks like you and me go through his script line by line, like a compiler
> would, and make derogatory comments where we can. Instead, I think he was
> just putting it out there as something you may (or may not) enjoy reading.
> I really didn't get the impression that he wanted or was seeking any human
> compilers.

That is right.

> Note, BTW, that I did go and read his post (on linked in) and if I *WAS* so
> inclined, I could make some (in fact, quite a few) human compiler comments,
> but I do not intend on doing so.

I do not mind getting them. :-D
Put I think it would be best at the post itself, because then it will
reach the most people.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile

<87v8qs9jp9.fsf_-_@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5641&group=comp.unix.shell#5641

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 19:33:54 +0200
Organization: Decebal Computing
Lines: 25
Message-ID: <87v8qs9jp9.fsf_-_@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="134818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+n/So/VbFqiqNpFyKOMo0SqPZ0j8CVzzo="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:MfljmwNp87N+6KDLUVtLzsD1ifc=
sha1:ucM2RBtLhkhZoCD3yL4ZIKoQrW4=
 by: Cecil Westerhof - Tue, 16 Aug 2022 17:33 UTC

"Auric__" <not.my.real@email.address> writes:

> Cecil Westerhof wrote:
>
>> For people who know Bash, but like to learn write (better) scripts I
>> wrote an article about a script I wrote to create and add a swapfile:
>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>
>> You can get the script here:
>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwap
>> File.sh
>
> In the future, please don't multi-post. Crosspost instead. (Also found in
> alt.os.linux.)

I would not know how, but that is not a problem: that is easy to find
out I think.

But I often have seen rants about cross-posting. So I was wondering
what the consensus is about this in the newsgroup.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile

<20220816195838.03e42896@nx-74205>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5642&group=comp.unix.shell#5642

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: thoron...@telenet.be (Aragorn)
Newsgroups: comp.unix.shell
Subject: Re: cross-post, or multi-post Was: Re: Wrote a bash script to
create and add a swapfile
Date: Tue, 16 Aug 2022 19:58:38 +0200
Organization: A noiseless patient Strider
Lines: 42
Message-ID: <20220816195838.03e42896@nx-74205>
References: <874jyccqbs.fsf@munus.decebal.nl>
<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
<87v8qs9jp9.fsf_-_@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: reader01.eternal-september.org; posting-host="3a2e7482b3f77585ddf9c89bfb4669cb";
logging-data="45480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Qj9c8o2kgkjKhkhCXyj2r"
Cancel-Lock: sha1:W5gKVrs6uCdxE0L7IRlI17sYBls=
X-Newsreader: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu)
 by: Aragorn - Tue, 16 Aug 2022 17:58 UTC

On 16.08.2022 at 19:33, Cecil Westerhof scribbled:

> "Auric__" <not.my.real@email.address> writes:
>
> > Cecil Westerhof wrote:
> >
> >> For people who know Bash, but like to learn write (better) scripts
> >> I wrote an article about a script I wrote to create and add a
> >> swapfile:
> >> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
> >>
> >> You can get the script here:
> >> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwap
> >> File.sh
> >
> > In the future, please don't multi-post. Crosspost instead. (Also
> > found in alt.os.linux.)
>
> I would not know how, but that is not a problem: that is easy to find
> out I think.

You simply put multiple newsgroups in the "To:" or "Newsgroups:" field
of your newsreader's editor — I'm not familiar with Gnus, sorry — with
the names separated by a comma.

A good newsreader will recognize cross-posted threads and will not open
them as a new thread when you select a different newsgroup for reading
and said group was included in the cross-post list — it will however
display the followups if they themselves were not cross-posted.

If you multi-post on the other hand, then the newsreader does not see
any correlation and will regard it as just another new and standalone
thread. And of course, people won't be able to reply to your thread
just once and have their reply propagated to the same other newsgroups
where the thread is posted all in one go.

--
With respect,
= Aragorn

Re: Meta re: the state of the economy and various other topics

<87mtc49gxs.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5643&group=comp.unix.shell#5643

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Tue, 16 Aug 2022 20:33:35 +0200
Organization: Decebal Computing
Lines: 34
Message-ID: <87mtc49gxs.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <20220816193718.2fc987e3@nx-74205>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="147302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WYOEGRRl8ubQftFkjnGziu1WGtVzf5BI="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:P/kSFnYydTujuGiF0L5pTTuK1r0=
sha1:f/eq2q43IxQX1INqKXEtLSeH/WU=
 by: Cecil Westerhof - Tue, 16 Aug 2022 18:33 UTC

Aragorn <thorongil@telenet.be> writes:

> I have interacted with Cecil in person off of Usenet several years ago
> regarding a presentation he was creating on account of systemd — he
> himself may not remember that anymore, but I happen to have an eidetic
> memory.

I do not remember this instance, but I know that most of the time I
appreciate your posts.

> Cecil is not the kind of person you are describing above. He is
> someone who's eager to contribute to the FLOSS community, he
> absolutely loves scripting in GNU bash, and he takes pride in his work.

Thank you for the compliment.

> From my prior interactions with Cecil, I know that he always welcomes
> all constructive commentary. But he wasn't fishing for it, and
> knowing

Yes: I always like to learn.

> him, his code is probably sufficiently good already, even if perhaps
> not perfect.

You make me blush.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile

<87ilms9gug.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5644&group=comp.unix.shell#5644

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile
Date: Tue, 16 Aug 2022 20:35:35 +0200
Organization: Decebal Computing
Lines: 45
Message-ID: <87ilms9gug.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
<87v8qs9jp9.fsf_-_@munus.decebal.nl> <20220816195838.03e42896@nx-74205>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader01.eternal-september.org; posting-host="abe3705896768d091071cc86fd418dbb";
logging-data="147302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HW1IbhE33sK9Z9mQGF/rM0eP4FCp/bHU="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:mT0ohHYhwY7ttijp/4ejxsgg018=
sha1:iflhH4bZ09AtxGTI0lqQYlxneSE=
 by: Cecil Westerhof - Tue, 16 Aug 2022 18:35 UTC

Aragorn <thorongil@telenet.be> writes:

> On 16.08.2022 at 19:33, Cecil Westerhof scribbled:
>
>> "Auric__" <not.my.real@email.address> writes:
>>
>> > Cecil Westerhof wrote:
>> >
>> >> For people who know Bash, but like to learn write (better) scripts
>> >> I wrote an article about a script I wrote to create and add a
>> >> swapfile:
>> >> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>> >>
>> >> You can get the script here:
>> >> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwap
>> >> File.sh
>> >
>> > In the future, please don't multi-post. Crosspost instead. (Also
>> > found in alt.os.linux.)
>>
>> I would not know how, but that is not a problem: that is easy to find
>> out I think.
>
> You simply put multiple newsgroups in the "To:" or "Newsgroups:" field
> of your newsreader's editor — I'm not familiar with Gnus, sorry — with
> the names separated by a comma.
>
> A good newsreader will recognize cross-posted threads and will not open
> them as a new thread when you select a different newsgroup for reading
> and said group was included in the cross-post list — it will however
> display the followups if they themselves were not cross-posted.
>
> If you multi-post on the other hand, then the newsreader does not see
> any correlation and will regard it as just another new and standalone
> thread. And of course, people won't be able to reply to your thread
> just once and have their reply propagated to the same other newsgroups
> where the thread is posted all in one go.

Well, if I do not see people starkly disagreeing I will start
cross-posting.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile

<op.1q0fnzhna3w0dxdave@hodgins.homeip.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5645&group=comp.unix.shell#5645

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: dwhodg...@nomail.afraid.org (David W. Hodgins)
Newsgroups: comp.unix.shell
Subject: Re: cross-post, or multi-post Was: Re: Wrote a bash script to create
and add a swapfile
Date: Tue, 16 Aug 2022 16:10:37 -0400
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <op.1q0fnzhna3w0dxdave@hodgins.homeip.net>
References: <874jyccqbs.fsf@munus.decebal.nl>
<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
<87v8qs9jp9.fsf_-_@munus.decebal.nl> <20220816195838.03e42896@nx-74205>
<87ilms9gug.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 8bit
Injection-Info: reader01.eternal-september.org; posting-host="dbd11ab74656c8101bf7622239f39236";
logging-data="175871"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Lr7UIU3/Rgv8Vda+G8Att6nuMo2+s7z8="
User-Agent: Opera Mail/12.16 (Linux)
Cancel-Lock: sha1:zKdk7pC5Iw3z6uodAikbsKG7JMQ=
 by: David W. Hodgins - Tue, 16 Aug 2022 20:10 UTC

On Tue, 16 Aug 2022 14:35:35 -0400, Cecil Westerhof <Cecil@decebal.nl> wrote:
> Well, if I do not see people starkly disagreeing I will start
> cross-posting.

Use of cross-posting is ok as long as there are not too many groups, and it's
on topic for all included groups.

Try to limit it to no more than 3 groups.

Regards, Dave Hodgins

Re: cross-post, or multi-post

<831qtfq5ma.fsf_-_@helmutwaitzmann.news.arcor.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5646&group=comp.unix.shell#5646

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!aioe.org!scIElgHJAN9TXI7f0CAVhQ.user.46.165.242.75.POSTED!not-for-mail
From: nn.throt...@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: cross-post, or multi-post
Date: Tue, 16 Aug 2022 22:46:05 +0200
Organization: Aioe.org NNTP Server
Message-ID: <831qtfq5ma.fsf_-_@helmutwaitzmann.news.arcor.de>
References: <874jyccqbs.fsf@munus.decebal.nl>
<XnsAEF555EF8686Fauricauricauricauric@88.198.57.247>
<87v8qs9jp9.fsf_-_@munus.decebal.nl>
<20220816195838.03e42896@nx-74205> <87ilms9gug.fsf@munus.decebal.nl>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Info: gioia.aioe.org; logging-data="2101"; posting-host="scIElgHJAN9TXI7f0CAVhQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)
Cancel-Lock: sha1:4h9CM+C+QzsikprjtwnyeI4Oe1E=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
X-Notice: Filtered by postfilter v. 0.9.2
 by: Helmut Waitzmann - Tue, 16 Aug 2022 20:46 UTC

Cecil Westerhof <Cecil@decebal.nl>:
>
>Well, if I do not see people starkly disagreeing I will start
>cross-posting.

Yes, make it so.  You might read the article

Subject: FAQ: Current Usenet spam thresholds and guidelines
Summary: This posting contains the current Spam definitions, thresholds,
and guidelines, as used by most major spam cancellers and news
administrators.
From: tskirvin@killfile.org (Tim Skirvin)
Reply-To: tskirvin@killfile.org
Newsgroups: news.admin.net-abuse.usenet, news.admin.net-abuse.misc,
news.answers
Followup-To: news.admin.net-abuse.usenet
Date: Sun, 14 Aug 2022 00:02:02 +0000
Expires: Sun, 25 Sep 2022 00:02:02 GMT
Message-ID: <spam-faq.20220814000202$1c02@news.killfile.org>

(which itself is a crossposting) regarding excessive crossposting
and excessive multi‐posting, though, to see what a well‐behaved
crossposting might be.

Re: Wrote a bash script to create and add a swapfile

<tdig3k$e1sd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5647&group=comp.unix.shell#5647

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: janis_pa...@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 12:32:20 +0200
Organization: A noiseless patient Spider
Lines: 114
Message-ID: <tdig3k$e1sd$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 10:32:20 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="9c1fe1a1415706e0244133710f4c94eb";
logging-data="460685"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NTRIz/JR3zsjmZvZ8LY6W"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:61JGQvUYzAeQf7xHUrHZqdRNpLc=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <87r11g9jjs.fsf@munus.decebal.nl>
 by: Janis Papanagnou - Wed, 17 Aug 2022 10:32 UTC

On 16.08.2022 19:37, Cecil Westerhof wrote:
> Cecil Westerhof <Cecil@decebal.nl> writes:
>
>> For people who know Bash, but like to learn write (better) scripts I
>> wrote an article about a script I wrote to create and add a swapfile:
>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>
>> You can get the script here:
>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>
> The script my post explains.

Since you spread (thus multiply) knowledge about scripting I'd like to
give a few comments...

> #!/usr/bin/env bash
>
> set -o errexit
> set -o nounset
>
>
>
> function getFreeGB {
> df -BG $(dirname $1) | \
> tail -n 1 | \
> awk '{print substr($4, 1, length($4) - 1)}'
> }

In scripting the backslashes as a line continuation are a bad concept
since you don't see whether there's whitespace characters (other than
the newline character) there. Specifically a final pipe symbol doesn't
need any explicit textual line continuation so it can be anyway just
omitted.

Since you want only the last line of the df output you can let awk do
that job; at the end of processing the last processed input line is
still available in the END section, a simple change

df -BG $(dirname $1) |
awk 'END {print substr($4, 1, length($4) - 1)}'

and since you want to strip just the numerical part from the field $4
you can simplify that substr/langth by doing numeric "type casting"

df -BG $(dirname $1) |
awk 'END {print 0+$4}'

Below I am wondering why you are not consistently using braces when
expanding variables; we see ${0} and $2, and we see ${_gbFree} and
$_gb. I think this is confusing for folks that are learning shell -
as I understood that this was the (or one) intention of your post.
Whatever you prefer, but mixing is not a good thing as a paragon.

Since you're using a modern shell like bash (and obviously don't
restrict to POSIX) I wonder why you don't use arithmetic expressions.
Instead of

if [[ ${_gbFree} -le $(($_gb * 4)) ]]

there's the much clearer

if (( _gbFree <= _gb * 4 ))

Finally, and especially if a variable is named "File", I'd quote the
variable expansions ("${_swapFile}"), as a paragon for the learning
folks, but also as an actual safety measure (since it's initialized
by the caller through $1, which can contain white-space characters).

Note: I haven't read the article behind your posted link, and I also
haven't inspected every line of your code; my comments are just from
a few quite obvious observations in the posted shell source code.

Janis

>
> function giveError {
> echo $1
> exit 1
> }
>
>
> declare -r _scriptName=$(basename ${0})
> if [[ $(id --user) -ne 0 ]] ; then
> giveError "${_scriptName} should be run as root"
> fi
> if [[ $# -ne 2 ]] ; then
> giveError "ERROR: ${_scriptName} SWAPFILE GB"
> fi
> declare -r _swapFile=$1
> declare -ir _gb=$2
>
> if [[ -e ${_swapFile} ]] ; then
> giveError "${_swapFile} already exists"
> fi
> declare -ir _gbFree=$(getFreeGB ${_swapFile})
> # Make sure swapfile is less as a quarter of free space
> if [[ ${_gbFree} -le $(($_gb * 4)) ]] ; then
> giveError "Not enough space for swap file ($_gb, ${_gbFree})"
> fi
> echo Current Swap:
> swapon
> echo
> date "+%T: Creating ${_swapFile}"
> dd if=/dev/zero of=${_swapFile} bs=1024 count=$(($_gb * 1024 ** 2))
> echo
> chmod 600 ${_swapFile}
> mkswap ${_swapFile}
> swapon ${_swapFile}
> echo New Swap:
> swapon
>

Re: Meta re: the state of the economy and various other topics

<tditm4$f9b6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5649&group=comp.unix.shell#5649

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 09:24:04 -0500
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <tditm4$f9b6$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 14:24:04 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="501094"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/zEbbumCbjD8n7t2mQ7FZ"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:rCgU/YVmtoKtszqID++hNiRr+2E=
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
In-Reply-To: <87zgg49juu.fsf@munus.decebal.nl>
X-Antivirus-Status: Clean
Content-Language: en-US
 by: Ed Morton - Wed, 17 Aug 2022 14:24 UTC

On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
<snip>
> I created a bash group on LinkedIn and there was a question about how
> to learn to program in bash. So I wrote a script and an article
> explaining the script with hopefully interesting tips for people how
> to create their own scripts.
>
> I just thought/hoped it could be interesting for people using this
> newsgroup.

Then I wish you had posted your script and article here and pointed
people from LinkedIn here instead of doing it the other way around.
There's already far too many places for people to ask and look up
answers to shell questions (this NG, other usenet groups, stackexchange,
stackoverflow, unix.com, etc., etc.), the last thing the larger
community of shell users needs is yet another location (LinkedIn!) to
have to look for answers in.

Ed.

Re: Wrote a bash script to create and add a swapfile

<tdiuaj$f9b7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5650&group=comp.unix.shell#5650

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 09:34:59 -0500
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <tdiuaj$f9b7$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 14:34:59 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="501095"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/oKa9em1/7W2+wCX9+4tqJ"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:RLErHxryDbKn+/GwetaQW78ZBVw=
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
Content-Language: en-US
In-Reply-To: <87r11g9jjs.fsf@munus.decebal.nl>
 by: Ed Morton - Wed, 17 Aug 2022 14:34 UTC

On 8/16/2022 12:37 PM, Cecil Westerhof wrote:
> Cecil Westerhof <Cecil@decebal.nl> writes:
>
>> For people who know Bash, but like to learn write (better) scripts I
>> wrote an article about a script I wrote to create and add a swapfile:
>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>
>> You can get the script here:
>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>
> The script my post explains.

You should copy/paste your script into http://shellcheck.net and fix the
issues it tells you about (e.g. the missing quotes in several places).

A few additional things I noticed:

You're using `{...}` unnecessarily everywhere, I think maybe you're
mistaking what curly brackets do (just separate a variable from
concatenated text) vs what double quotes do (protect your variable from
globbing, word splitting, and filename expansion).

The use of `function foo {` is non-portable, use `foo() {` instead.

When printing error messages (e.g. inside "giveError()") add `>&2` so
the message goes to stderr instead of stdout.

Ed.

>
>
> #!/usr/bin/env bash
>
> set -o errexit
> set -o nounset
>
>
>
> function getFreeGB {
> df -BG $(dirname $1) | \
> tail -n 1 | \
> awk '{print substr($4, 1, length($4) - 1)}'
> }
>
> function giveError {
> echo $1
> exit 1
> }
>
>
> declare -r _scriptName=$(basename ${0})
> if [[ $(id --user) -ne 0 ]] ; then
> giveError "${_scriptName} should be run as root"
> fi
> if [[ $# -ne 2 ]] ; then
> giveError "ERROR: ${_scriptName} SWAPFILE GB"
> fi
> declare -r _swapFile=$1
> declare -ir _gb=$2
>
> if [[ -e ${_swapFile} ]] ; then
> giveError "${_swapFile} already exists"
> fi
> declare -ir _gbFree=$(getFreeGB ${_swapFile})
> # Make sure swapfile is less as a quarter of free space
> if [[ ${_gbFree} -le $(($_gb * 4)) ]] ; then
> giveError "Not enough space for swap file ($_gb, ${_gbFree})"
> fi
> echo Current Swap:
> swapon
> echo
> date "+%T: Creating ${_swapFile}"
> dd if=/dev/zero of=${_swapFile} bs=1024 count=$(($_gb * 1024 ** 2))
> echo
> chmod 600 ${_swapFile}
> mkswap ${_swapFile}
> swapon ${_swapFile}
> echo New Swap:
> swapon
>

Re: Wrote a bash script to create and add a swapfile

<tdiui4$9goo$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5651&group=comp.unix.shell#5651

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 14:39:00 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tdiui4$9goo$1@news.xmission.com>
References: <874jyccqbs.fsf@munus.decebal.nl> <87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
Injection-Date: Wed, 17 Aug 2022 14:39:00 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="312088"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 17 Aug 2022 14:39 UTC

In article <tdiuaj$f9b7$1@dont-email.me>,
Ed Morton <mortonspam@gmail.com> wrote:
>On 8/16/2022 12:37 PM, Cecil Westerhof wrote:
>> Cecil Westerhof <Cecil@decebal.nl> writes:
>>
>>> For people who know Bash, but like to learn write (better) scripts I
>>> wrote an article about a script I wrote to create and add a swapfile:
>>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>>
>>> You can get the script here:
>>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>>
>> The script my post explains.
>
>You should copy/paste your script into http://shellcheck.net and fix the
>issues it tells you about (e.g. the missing quotes in several places).

Here comes the human compiler.

As predicted.

--
Which of these is the crazier bit of right wing lunacy?
1) We've just had another mass shooting; now is not the time to be talking about gun control.

2) We've just had a massive hurricane; now is not the time to be talking about climate change.

Re: Wrote a bash script to create and add a swapfile

<tdiukl$f9b7$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5652&group=comp.unix.shell#5652

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 09:40:21 -0500
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tdiukl$f9b7$2@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 14:40:21 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="501095"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fbMxG8PH6NkqS0Wlj/Peq"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:Qd+ddW1H6IGuUZOcYKhS6t6cEyA=
X-Antivirus-Status: Clean
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
In-Reply-To: <tdig3k$e1sd$1@dont-email.me>
Content-Language: en-US
 by: Ed Morton - Wed, 17 Aug 2022 14:40 UTC

On 8/17/2022 5:32 AM, Janis Papanagnou wrote:
> On 16.08.2022 19:37, Cecil Westerhof wrote:

<snip>

> Since you want only the last line of the df output you can let awk do
> that job; at the end of processing the last processed input line is
> still available in the END section, a simple change
>
> df -BG $(dirname $1) |
> awk 'END {print substr($4, 1, length($4) - 1)}'

At the end of processing the last processed input line is not guaranteed
to still available in the END section.

The value of $4 or any other field or $0 is undefined (by POSIX) in the
END section. In some awk variants it will be the $4 from the last record
read as you want, but in others it'll be null, and in others still it
could be anything else. To do what you show above portably in all awks
would be:

awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'

Regards,

Ed.

Re: Wrote a bash script to create and add a swapfile

<20220817170126.7dcb0795@nx-74205>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5653&group=comp.unix.shell#5653

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: thoron...@telenet.be (Aragorn)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 17:01:26 +0200
Organization: A noiseless patient Strider
Lines: 40
Message-ID: <20220817170126.7dcb0795@nx-74205>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl>
<tdiuaj$f9b7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: reader01.eternal-september.org; posting-host="1956e56c12243f2d1ebb1c83a81a0e90";
logging-data="45480"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/giIStuipmxAZ2DedwNRNR"
Cancel-Lock: sha1:k0+ItM/jDpGslNkV+TXaj7xb9+Q=
X-Newsreader: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu)
 by: Aragorn - Wed, 17 Aug 2022 15:01 UTC

On 17.08.2022 at 09:34, Ed Morton scribbled:

> You're using `{...}` unnecessarily everywhere, I think maybe you're
> mistaking what curly brackets do (just separate a variable from
> concatenated text) vs what double quotes do (protect your variable
> from globbing, word splitting, and filename expansion).

There's nothing wrong with being consistent in using accolades for all
variable names.

For one, it makes shell scripts easier to understand for novices than
the reserved use of accolades for when the variable name is being
concatenated with another string only wile not using the accolades
elsewhere. And in the environment where I have to explain things or
solve problems by way of shell commands and scripts, virtually 95% of
the audience is an absolute novice.

For that reason alone, I myself also consistently use the accolade
notation inside scripts intended to be saved on disk, although I'll
admit that I commonly omit them in one-liners, and especially so on my
own system here.

> The use of `function foo {` is non-portable, use `foo() {` instead.

I agree with that, and I myself always write my scripts in the most
portable way, but the OP has very clearly indicated that it is a bash
script, and that it's specifically intended for use in GNU/Linux, where
GNU bash is still the main shell.

I don't even know how many other UNIX variants would support the
use of swap files instead of a dedicated swap partition. macOS and
Solaris/OpenIndiana, yes — macOS uses them by default, even. The current
batch of BSDs, maybe. But I suspect that HP/UX, AIX and whatever OSF/1
installations might still remain in use today do not.

--
With respect,
= Aragorn

Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile

<XnsAEF658501A211auricauricauricauric@88.198.57.247>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5654&group=comp.unix.shell#5654

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: not.my.r...@email.address (Auric__)
Newsgroups: comp.unix.shell
Subject: Re: cross-post, or multi-post Was: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 15:40:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <XnsAEF658501A211auricauricauricauric@88.198.57.247>
References: <874jyccqbs.fsf@munus.decebal.nl> <XnsAEF555EF8686Fauricauricauricauric@88.198.57.247> <87v8qs9jp9.fsf_-_@munus.decebal.nl> <20220816195838.03e42896@nx-74205> <87ilms9gug.fsf@munus.decebal.nl> <op.1q0fnzhna3w0dxdave@hodgins.homeip.net>
Injection-Date: Wed, 17 Aug 2022 15:40:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="aaa0d53537d066e96f2531f3b4b4e4f9";
logging-data="516719"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oW8pJZgmojLO6SAVzkZzz"
User-Agent: Xnews/2009.05.01
Cancel-Lock: sha1:KoKYfeGstXEit++AkTfpTJydDRE=
X-Face: +,&^!i3LPqz7/qfxgF[JJqAP^>bTVLZ-zj})PmI{auZ']fwMM4mh`$]b0sacD4p@R[yU'Mf=.T}|aW6^#_lm6U|e|/#d:nfRn29,GBLvX=ygRH(?h.=KFfJ\INamt#H|)k@,x[ko$(d~iAo'<1XzB@%];
 by: Auric__ - Wed, 17 Aug 2022 15:40 UTC

David W. Hodgins wrote:

> On Tue, 16 Aug 2022 14:35:35 -0400, Cecil Westerhof <Cecil@decebal.nl>
> wrote:
>> Well, if I do not see people starkly disagreeing I will start
>> cross-posting.
>
> Use of cross-posting is ok as long as there are not too many groups, and
> it's on topic for all included groups.

Agreed. And crossposting is *always* better than multi-posting. Multi-posting
is the spammer's tactic; crossposting invites discussion between people who
may not normally interact.

> Try to limit it to no more than 3 groups.

A few more *might* be acceptable if there's good reason for posting in 4 or 5
or whatever, but past a certain point, you need to ask yourself, "Do I
*really* need to post this in 12 groups?"

--
When I die, I want the people I did group projects with to
lower me into the ground so they can let me down one last time.

Re: Wrote a bash script to create and add a swapfile

<tdj279$fpcl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5655&group=comp.unix.shell#5655

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortons...@gmail.com (Ed Morton)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 10:41:30 -0500
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <tdj279$fpcl$1@dont-email.me>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdiuaj$f9b7$1@dont-email.me>
<20220817170126.7dcb0795@nx-74205>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Aug 2022 15:41:30 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="583b416d722c5905b1ca740c6996e3e8";
logging-data="517525"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yCI+wVmrLm0fzoMFHsuz9"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.1.0
Cancel-Lock: sha1:4GF1qEoNAg6yXaHW027/MJ5O+To=
X-Antivirus: Avast (VPS 220817-4, 8/17/2022), Outbound message
X-Antivirus-Status: Clean
In-Reply-To: <20220817170126.7dcb0795@nx-74205>
Content-Language: en-US
 by: Ed Morton - Wed, 17 Aug 2022 15:41 UTC

On 8/17/2022 10:01 AM, Aragorn wrote:
> On 17.08.2022 at 09:34, Ed Morton scribbled:
>
>> You're using `{...}` unnecessarily everywhere, I think maybe you're
>> mistaking what curly brackets do (just separate a variable from
>> concatenated text) vs what double quotes do (protect your variable
>> from globbing, word splitting, and filename expansion).
>
> There's nothing wrong with being consistent in using accolades for all
> variable names.

I wouldn't have mentioned the curly brackets on their own as they're
harmless but I pointed out them out as I think the OP may be using them
thinking they will do what double quotes actually do as far as
protecting the variable.

Ed.

Re: Wrote a bash script to create and add a swapfile

<87a682anfi.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5656&group=comp.unix.shell#5656

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 17:40:17 +0200
Organization: Decebal Computing
Lines: 130
Message-ID: <87a682anfi.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="519197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aTiar/Up6v7k1IYQnM33Pm0uJew19HXc="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:Mpa4YKixy6cyqloLl06tX3dXVoA=
sha1:glJFqwZMyDlxT274ROflLf1XNSo=
 by: Cecil Westerhof - Wed, 17 Aug 2022 15:40 UTC

Janis Papanagnou <janis_papanagnou@hotmail.com> writes:

> On 16.08.2022 19:37, Cecil Westerhof wrote:
>> Cecil Westerhof <Cecil@decebal.nl> writes:
>>
>>> For people who know Bash, but like to learn write (better) scripts I
>>> wrote an article about a script I wrote to create and add a swapfile:
>>> https://www.linkedin.com/pulse/script-add-swap-file-cecil-westerhof
>>>
>>> You can get the script here:
>>> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/addSwapFile.sh
>>
>> The script my post explains.
>
> Since you spread (thus multiply) knowledge about scripting I'd like to
> give a few comments...

Thanks I already extensively rewrote the script based on feedback. You
bring forth some other good points.

>> function getFreeGB {
>> df -BG $(dirname $1) | \
>> tail -n 1 | \
>> awk '{print substr($4, 1, length($4) - 1)}'
>> }
>
> In scripting the backslashes as a line continuation are a bad concept
> since you don't see whether there's whitespace characters (other than
> the newline character) there. Specifically a final pipe symbol doesn't
> need any explicit textual line continuation so it can be anyway just
> omitted.

I know that you have to be careful that the backslash is the last
character on the line, but I find it important that lines (if
possible) are less as 80 characters.
I did not know that the final pipe symbol does not need an explicit
context. That is going to make my live easier.

> Since you want only the last line of the df output you can let awk do
> that job; at the end of processing the last processed input line is
> still available in the END section, a simple change

I was wondering about that, wanted to verify it, but 'needed' to
publish something fast.

> df -BG $(dirname $1) |
> awk 'END {print substr($4, 1, length($4) - 1)}'
>
> and since you want to strip just the numerical part from the field $4
> you can simplify that substr/langth by doing numeric "type casting"
>
> df -BG $(dirname $1) |
> awk 'END {print 0+$4}'

That is also an huge improvement.

I had already added that the partition should be on /dev and that a
warning is given when the file system is btrfs.
So the function has become:
function getFreeGB {
fields="$(df -BG -T $(dirname $1) | awk 'END { print $1, $2, 0 + $5 }')"
read dev fs gb <<< "${fields}"
# Check $dev starts with /dev/
if [[ ! $dev =~ ^/dev/.* ]]; then
giveError "File system is not on /dev ($dev)" 5
fi
if [[ $fs == btrfs ]] ; then
echo "This script is not guaranted to work with btrfs" >&2
fi
echo $gb
}

> Below I am wondering why you are not consistently using braces when
> expanding variables; we see ${0} and $2, and we see ${_gbFree} and
> $_gb. I think this is confusing for folks that are learning shell -
> as I understood that this was the (or one) intention of your post.
> Whatever you prefer, but mixing is not a good thing as a paragon.

Oops, that I used ${0} was certainly wrong. :'-(

Let me explain. In the past people where really annoyed by me using
braces. "It is not necessary." But there are some cases where they are
important. That is why I decided that when the length of a name is not
more as 4 characters long I will not use braces and otherwise I will.
But I should explain that.

> Since you're using a modern shell like bash (and obviously don't
> restrict to POSIX)

I am a bit on the fence with that. In a way I like to confirm to
POSIX. But not rigorously. For example I use long options, but
mentions what the corresponding short ones are. Handy for people that
have a POSIX compliant awk.

> I wonder why you don't use arithmetic expressions. Instead of
>
> if [[ ${_gbFree} -le $(($_gb * 4)) ]]
>
> there's the much clearer
>
> if (( _gbFree <= _gb * 4 ))

Correct, implemented.

> Finally, and especially if a variable is named "File", I'd quote the
> variable expansions ("${_swapFile}"), as a paragon for the learning
> folks, but also as an actual safety measure (since it's initialized
> by the caller through $1, which can contain white-space characters).

You are right again. I 'always' say I want to use 'unnecessary'
checks, because I am (hopefully) not the only person that uses my
scripts. But I dropped the ball here. :'-(

> Note: I haven't read the article behind your posted link, and I also
> haven't inspected every line of your code; my comments are just from
> a few quite obvious observations in the posted shell source code.

It is very much appreciated.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<871qteamv5.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5657&group=comp.unix.shell#5657

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 17:52:30 +0200
Organization: Decebal Computing
Lines: 32
Message-ID: <871qteamv5.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl>
<87r11g9jjs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me>
<tdiukl$f9b7$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="521988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GTWwlhYGT16r1M2Rx7Hpx+xi8F63N+9s="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:9xzDgrJSz8SlQLAn7Ms5AGLsnZA=
sha1:ZY/NfQ32Jhs1i6+dsqBDChTMEk4=
 by: Cecil Westerhof - Wed, 17 Aug 2022 15:52 UTC

Ed Morton <mortonspam@gmail.com> writes:

> On 8/17/2022 5:32 AM, Janis Papanagnou wrote:
>> On 16.08.2022 19:37, Cecil Westerhof wrote:
>
> <snip>
>
>> Since you want only the last line of the df output you can let awk do
>> that job; at the end of processing the last processed input line is
>> still available in the END section, a simple change
>> df -BG $(dirname $1) |
>> awk 'END {print substr($4, 1, length($4) - 1)}'
>
> At the end of processing the last processed input line is not guaranteed
> to still available in the END section.
>
> The value of $4 or any other field or $0 is undefined (by POSIX) in the
> END section. In some awk variants it will be the $4 from the last record
> read as you want, but in others it'll be null, and in others still it
> could be anything else. To do what you show above portably in all awks
> would be:
>
> awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'

For me it works, but I should implement something like this then.

Thanks.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Meta re: the state of the economy and various other topics

<875yiqan1p.fsf@munus.decebal.nl>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5658&group=comp.unix.shell#5658

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.unix.shell
Subject: Re: Meta re: the state of the economy and various other topics
Date: Wed, 17 Aug 2022 17:48:34 +0200
Organization: Decebal Computing
Lines: 21
Message-ID: <875yiqan1p.fsf@munus.decebal.nl>
References: <874jyccqbs.fsf@munus.decebal.nl> <87mtc45okr.fsf@bsb.me.uk>
<tdg8tb$84fr$1@news.xmission.com> <87zgg49juu.fsf@munus.decebal.nl>
<tditm4$f9b6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader01.eternal-september.org; posting-host="c28d404ae6ede4d7a318b5c4d5a753d2";
logging-data="521988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UXdXe9Gx9/whOihUP4NRCUTOrLPvr+iI="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:Y0PNM+rDE23mhiaBdnbl7HopQrQ=
sha1:N2H8k32f/nwsiZ4nvPmqR01f1lY=
 by: Cecil Westerhof - Wed, 17 Aug 2022 15:48 UTC

Ed Morton <mortonspam@gmail.com> writes:

> On 8/16/2022 12:30 PM, Cecil Westerhof wrote:
> <snip>
>> I created a bash group on LinkedIn and there was a question about how
>> to learn to program in bash. So I wrote a script and an article
>> explaining the script with hopefully interesting tips for people how
>> to create their own scripts.
>> I just thought/hoped it could be interesting for people using this
>> newsgroup.
>
> Then I wish you had posted your script and article here and pointed
> people from LinkedIn here instead of doing it the other way around.

I do not think that will work. I love usenet, but we (users of usenet)
are a dying race. Most people do not even know it exists.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Re: Wrote a bash script to create and add a swapfile

<tdj3kg$9is2$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5659&group=comp.unix.shell#5659

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!csiph.com!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Wrote a bash script to create and add a swapfile
Date: Wed, 17 Aug 2022 16:05:36 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tdj3kg$9is2$1@news.xmission.com>
References: <874jyccqbs.fsf@munus.decebal.nl> <tdig3k$e1sd$1@dont-email.me> <tdiukl$f9b7$2@dont-email.me> <871qteamv5.fsf@munus.decebal.nl>
Injection-Date: Wed, 17 Aug 2022 16:05:36 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="314242"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Wed, 17 Aug 2022 16:05 UTC

In article <871qteamv5.fsf@munus.decebal.nl>,
Cecil Westerhof <Cecil@decebal.nl> wrote:
....
>> awk '{p=$4} END{print substr(p, 1, length(p) - 1)}'
>
>For me it works, but I should implement something like this then.

Or you could just use either mawk or gawk, which are known to work.

I always recommend against using plain old "awk" in a script, b/c you never
know what you are going to get.

Until fairly recently, using plain "awk" under Solaris got you a very old,
essentially non-functional version of AWK.

--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.

George Orwell

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor