Linux Format - UK (2019-12)

(Antfer) #1
12 LXF257 December 2019 http://www.linuxformat.com

ANSWERS


This will remove most, but not all, ANSI
codes. Fortunately, the ones it misses are
all covered by col. This program is part of
the util-linux package so it will already be
installed by your distro. As it also reads
from stdin and writes to stdout, you can
combine the two commands in one pass:
$ ansi2txt <typescript | col -b
>typescript.txt
This should work for you, but bear in
mind the warning from the ansi2txt man
page: “All ANSI codes are simply ignored,
including all cursor positioning ones.
Sometimes this is what you want,
sometimes it isn’t.”

Q


Pi in the middle
I recently acquired a Raspberry Pi
3 B+ (yes, I’m late to the Pi party!).
I have a use case in mind for it that
I’d like some guidance with.
We are going travelling in a few
months and I’m looking for a way of
using the Pi as a headless and input-
device-less conduit to upload batches of
photos to the cloud whenever we stay in
a hostel with wireless internet. Physically
getting the SD card from the camera
connected to the Pi is trivial – I have a
small USB card reader for that. My

Q


Anti-ANSI help
You recommended the use of the
script command to record terminal
output. This has worked well for me,
thank you, but there is one gotcha. If any
program I run produces coloured output,
the typescript file that script produces
has ANSI codes splattered all over it. Is
there a way to have script record only
plain ASCII? Alternatively, is there a
relatively easy way to remove these
codes from the file?
Suzette Blanchard

A


You cannot tell script to not record
those codes as it is designed to
produce a faithful record of the terminal
session that can be viewed with script
replay. For a quick way to view a clean
version of the file, the less pager removes
the majority of such codes. If you want to
remove them from the file permanently,
you can use the ansi2txt command.
This is not installed by default on most
distros but you will get it by installing the
colorized-logs package – their spelling,
not mine! It reads from standard input and
sends the cleaned-up version to standard
output, so run it like this:
$ ansi2txt <typescript >typescript.txt

Got a burning question about open source or the kernel?


Whatever your level, email it to [email protected]


stumbling block is that I think I’ll need
the wireless network on the Pi for two
distinct uses: to connect to a hostel’s
wireless and thus the internet, and to
pair with my phone so I can ssh in order
to run a script to upload the photos from
the SD card.
I don’t think I can have both wireless
modes ‘active’ at the same time. My
question probably boils down to, how
might I be able to connect the Pi to a
hostel’s wireless without having a
keyboard and display attached in order
to enter a wireless password? I think I
might have to set up the Pi as an access
point that I can connect my phone to,
download photos from the SD card onto
my phone, and then switch my phone to
connect to a hostel’s wireless in order to
do the upload as a separate step. But
this setup would likely restrict what else
I could use the Pi for, as it wouldn’t be
connected to the internet itself.
Matthew Wise

A


What you want to do should be
possible, but not that simple. The
first problem is connecting to the wireless
without a display and keyboard. With a
standard wireless setup, you can usually
edit the wpa_supplicant configuration file
to add an access point and password, but
many places do not use such a simple
setup. Many use a landing page where you
are required to use a web browser to login
before you can access the internet, which
is rather difficult without a display.
There is a way round this: add a second
wireless interface to the Pi on a USB
dongle. Then you can set up one interface
as an access point and connect to it from
your phone. Once the two are connected,
you can then use VNC to put the Pi’s
display on the phone and then set up the
wireless internet connection and copy your
files to the cloud.
You could possibly skip the second
wireless interface if your phone supports
USB networking: you could use a USB
cable for that connection and the Pi’s
onboard wireless to connect to the net.

If you really want to involve your Raspberry Pi in your travels, set it up at home as a repository for your photos.
A recent Pi is more than capable of running a single-user cloud.

Answers


Neil
Bothwick
uses old
Windows
DVDs to
carve Tux-
shaped toys.

12 LXF257 December 2019 http://www.linuxformat.com

Thiswillremovemost,butnotall,ANSI
codes.Fortunately,theonesit missesare
allcoveredbycol. Thisprogramispartof
theutil-linuxpackagesoit willalreadybe
installedbyyourdistro.Asit alsoreads
fromstdinandwritestostdout,youcan
combinethetwocommandsinonepass:
$ ansi2txt<typescript| col-b
>typescript.txt
Thisshouldworkforyou,butbearin
mindthewarningfromtheansi2txtman
page:“AllANSIcodesaresimplyignored,
includingallcursorpositioningones.
Sometimesthisiswhatyouwant,
sometimesit isn’t.”

Q


Piinthemiddle
I recentlyacquireda RaspberryPi
3 B+(yes,I’mlatetothePiparty!).
I havea usecaseinmindforit that
I’dlikesomeguidancewith.
Wearegoingtravellingina few
monthsandI’mlookingfora wayof
usingthePiasa headlessandinput-
device-lessconduittouploadbatchesof
photostothecloudwheneverwestayin
a hostelwithwirelessinternet.Physically
gettingtheSDcardfromthecamera
connectedtothePiistrivial– I havea
smallUSBcardreaderforthat.My

Q


Anti-ANSIhelp
Yourecommendedtheuseofthe
scriptcommandtorecordterminal
output.Thishasworkedwellforme,
thankyou,butthereisonegotcha.If any
programI runproducescolouredoutput,
thetypescriptfilethatscriptproduces
hasANSIcodessplatteredalloverit.Is
therea waytohavescriptrecordonly
plainASCII?Alternatively,istherea
relativelyeasywaytoremovethese
codesfromthefile?
SuzetteBlanchard

A


You cannot tell script to not record
those codes as it is designed to
produce a faithful record of the terminal
session that can be viewed with script
replay. For a quick way to view a clean
version of the file, the less pager removes
the majority of such codes. If you want to
remove them from the file permanently,
you can use the ansi2txt command.
Thisisnotinstalledbydefaultonmost
distrosbutyouwillgetit byinstallingthe
colorized-logspackage– theirspelling,
notmine!It readsfromstandardinputand
sendsthecleaned-upversiontostandard
output,sorunit likethis:
$ ansi2txt<typescript>typescript.txt

Gota burningquestionaboutopensourceorthekernel?


Whateveryourlevel,emailit [email protected]


stumbling block is that I think I’ll need
the wireless network on the Pi for two
distinct uses: to connect to a hostel’s
wireless and thus the internet, and to
pair with my phone so I can ssh in order
to run a script to upload the photos from
the SD card.
I don’t think I can have both wireless
modes ‘active’ at the same time. My
question probably boils down to, how
might I be able to connect the Pi to a
hostel’s wireless without having a
keyboard and display attached in order
to enter a wireless password? I think I
might have to set up the Pi as an access
point that I can connect my phone to,
download photos from the SD card onto
my phone, and then switch my phone to
connect to a hostel’s wireless in order to
do the upload as a separate step. But
this setup would likely restrict what else
I could use the Pi for, as it wouldn’t be
connected to the internet itself.
MatthewWise

A


What you want to do should be
possible, but not that simple. The
first problem is connecting to the wireless
without a display and keyboard. With a
standard wireless setup, you can usually
edit the wpa_supplicant configuration file
to add an access point and password, but
many places do not use such a simple
setup. Many use a landing page where you
are required to use a web browser to login
before you can access the internet, which
is rather difficult without a display.
There is a way round this: add a second
wireless interface to the Pi on a USB
dongle. Then you can set up one interface
as an access point and connect to it from
your phone. Once the two are connected,
you can then use VNC to put the Pi’s
display on the phone and then set up the
wireless internet connection and copy your
files to the cloud.
You could possibly skip the second
wireless interface if your phone supports
USB networking: you could use a USB
cable for that connection and the Pi’s
onboard wireless to connect to the net.

If you really want to involve your Raspberry Pi in your travels, set it up at home as a repository for your photos.
A recent Pi is more than capable of running a single-user cloud.

Answers


Neil
Bothwick
uses old
Windows
DVDs to
carve Tux-
shaped toys.
Free download pdf