The small linux problem thread

I lost my .bashrc and .bash_aliases file. Aliases stll work, just now file. Looked in home and etc (ubuntu server) - no luck.

When I encrypt a file with gpg, the encrypted version is output in the same directory as the source file.

Can that be changed?

With the gpg --encrypt --sign -r <email.address> file-name, the new file is placed in the same folder.

I canā€™t find anything in the manual about specifying were the output should be.
Eg, a .tar file is on hdd 1, and the .tar.gpg files should be created on hdd 2.

Since it is standard shell, replace filename with /mnt/mydisk/folder/filename, where /mnt/mydisk/folder is the folder you want to store the file in.

1 Like

If you use standard input to gpg, you can direct the output wherever you like.

1 Like

anyone know of an ansible module that will check for a file before running a command or do I have to register the output and then check it?

set -e is not exiting on bad substitution for me, is that normal?

did you try adding at the end

-o /home/donk/folder/newfilename.file

so

gpg --encrypt --sign -r <email.address> file-name -o /home/donk/folder/newfilename.file

or -This didnā€™t work for me

gpg --encrypt --sign -r <email.address> file-name > /folder/newfilename.randomextension

#IHaveNoIdea
#JustAskinForKicks

[edit added long ask arguments. I donā€™t know why discorse adds colours, unless itā€™s just on my screen]

Code syntax highlighting inside the code blocks. It is just failing to select the correct language, you would have to manually set it.

2 Likes

Thanks. I presume it would also explain why different bits got different colours?

Yep. Probably defaults to c++ or something.

1 Like

Yep, it tried and failed to detect language multiple times.

First one assumed it was a diff. Second one assumed xml probably. Dunno about 3rd.

2 Likes

Okay, what seemed to work for me was:

gpg --encrypt --sign -r <email.address> -o /path/to/folder/newfilename.file file-name
1 Like

Shell highlighting by default. Apparently starting a line with a hyphen is highlighted in red.

1 Like

Which of these is preferable (or is there a better way to get the default gateway interface)?

ip route show default | sed -e 's/^.*dev \([[:alnum:]]*\).*$/\1/'
ip route show default | grep -oP '(?<=dev )[^ ]*'

Technically the sed command is more portable, but it doesnā€™t really matter since ip isnā€™t. Neither is very legible.

I can use awk which looks better but is less safe. While this appears to work, I do see differences in ip output fields between Debian and RHEL distros which makes me hesitant to rely on it.

ip route show default | awk '{ print $5 }'

Is there any way to control what fields ip spits out like with nmcli? I donā€™t see anything in the docs.

Efficiency-wise, Iā€™d assume grep is the winner, but the execution times are all within .002 seconds, so who cares.

Personally, Iā€™d use grep, but thatā€™s because Iā€™m a pleb.

That said, Awk is probably the correct tool.

2 Likes

Yeah, if I really wanted to use awk, I guess I could:

ip route show default | awk '{for(i=1;i<=NF;i++)if($i=="dev")print $(i+1)}'

Pretty gross imo.

Iā€™ll have to think on it. For grep, I just donā€™t want to rely on non-portable flags.

1 Like

well you might want to just use sed or awk then.

2 Likes

nmcli

What would the nmcli command be?

Probably still have to grep the outputā€¦ I donā€™t think there is a way to directly show the gateway.

1 Like