You are not logged in.
Hello folks!
I have written a little script to show what packages are upgradeable:
1. the crontab:
@reboot apt-get update && apt list --upgradable > /home/naik/upgradeable
2. the script:
#!/bin/bash
list=$(cat ~/upgradeable | sed -n '1!p' | sed -e 's/\[*\]/\n/g')
date=$(ddate)
usr=$USER
echo 'Hallo '$usr'!'
echo $date
echo '#############UPGRADEABLE############'
echo $list
As you can see I inserted the 2nd sed call to replace anything between [] with a newline to beautify the output, but the result still looks like this:
(I`m piping the output through ponysay so i`m a little limited in terms of line length)
I tried several methods to achieve this, but none of them seems to work. Can somebody provide me with a solution to replace anything written in square brackets with newlines in any given text?
Thanks in advance and have a nice day Folks!
naik --greetz
Last edited by Naik (2017-06-24 18:06:59)
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
Hey Naik
This works for me:
empty@testbed:~ $ list=$(sed -n '1!p' upgradable | sed 's/\[.*\]//')
empty@testbed:~ $ echo "$list"
exim4-base/stable 4.89-2+deb9u1 amd64
exim4-config/stable 4.89-2+deb9u1 all
exim4-daemon-light/stable 4.89-2+deb9u1 amd64
libc-bin/stable 2.24-11+deb9u1 amd64
libc-dev-bin/stable 2.24-11+deb9u1 amd64
libc-l10n/stable 2.24-11+deb9u1 all
libc6/stable 2.24-11+deb9u1 amd64
libc6-dev/stable 2.24-11+deb9u1 amd64
linux-image-4.9.0-3-amd64/stable 4.9.30-2+deb9u1 amd64
linux-libc-dev/stable 4.9.30-2+deb9u1 amd64
locales/stable 2.24-11+deb9u1 all
multiarch-support/stable 2.24-11+deb9u1 amd64
empty@testbed:~ $
No need for bash with this script though (no bashims), a simple /bin/sh shebang will suffice
EDIT:
I`m piping the output through ponysay so i`m a little limited in terms of line length
Try the -W flag in ponysay to set the maximum width of the character's speech (or thought) bubble:
empty@Xanadu:~ $ screenfetch | ponysay -W120
______________________________________________________________________________________
/ -` \
| .o+` empty@Xanadu |
| `ooo/ OS: Arch Linux |
| `+oooo: Kernel: x86_64 Linux 4.11.6-1-hardened |
| `+oooooo: Uptime: 1h 10m |
| -+oooooo+: Packages: 939 |
| `/:-:++oooo+: Shell: mksh |
| `/++++/+++++++: Resolution: 1920x1080 |
| `/++++++++++++++: DE: GNOME |
| `/+++ooooooooooooo/` WM: GNOME Shell |
| ./ooosssso++osssssso+` WM Theme: CustomFontTheme |
| .oossssso-````/ossssss+` GTK Theme: Arc [GTK2/3] |
| -osssssso. :ssssssso. Icon Theme: Arc |
| :osssssss/ osssso+++. Font: Sans 11 |
| /ossssssss/ +ssssooo/- CPU: Intel Core i5-4330M @ 4x 3.5GHz [14.0°C] |
| `/ossssso+/:- -:/+osssso+- GPU: Mesa DRI Intel(R) Haswell Mobile |
| `+sso+:-` `.-/+oso: RAM: 1421MiB / 7908MiB |
| `++:. `-/+/ |
\ .` `/ /
--------------------------------------------------------------------------------------
\
\
\
▄▄▄▄▄ ▄▄▄▄▄
▄▄█████▄▄█████▄▄ ▄▄▄▄▄
███▄▄▄██████████▄█▄████
▄▄▄▄▄██▄█████████████▄▀
▄▄████████▄▄▄▄▄▄▄█▄▀▄█▄▀
▀▄█▄███████▄▄▄██▄▄ ▀▄▄█
██▄████▄▄███▄▄███ █▄▄▀
▄▄███▄▄█████▄█▄█████▀
▄▄▄▄▄▄▄▄ ▀▄█▄▄█▄▄█████▄███████
▄▄████████▄▄ ▀▀▄█▄▄██▄██████▄▄▄▀
███████▄▀▀▄▄▄▄▄▄▄▄▄▄▄█▄████▄█▀▀▀▀▀▀
▀▄███▄██ ▄▄▄▄▄▄▄▄▄▄██▄▄█████
▀▄█████ ██▄▄██▄▄▄▄▄███████
▄▄▄▄█▄█████▀▄▄█▄█▄█▄▄▄▄███▄▀
████████▄▄▄▀▄▄███▄█▄▄▄▄█████
▀▄▄█▄██ ██████▄▄▀ ██████
█▄ ▀▄▄██ ████████ ████▄█▄
▀▄▄▄▄▄██ █████████ ███████
▀▄▄▄▀ █████████ █████▄▄█▄
███████▄▄▄█ ███████▄█
█▄▄▄▄▄▄█ █▄▄▄▄▄█
empty@Xanadu:~ $
Ponysay rules!
Last edited by Head_on_a_Stick (2017-06-24 10:56:32)
Offline
Thread moved to Basic Help & Support, the Scripts &c section is for guides and tutorials.
Offline
Shorter version:
empty@testbed:~ $ list=$(awk -F"/" '!/Listing/{print $1}' upgradable)
empty@testbed:~ $ echo "$list"
exim4-base
exim4-config
exim4-daemon-light
libc-bin
libc-dev-bin
libc-l10n
libc6
libc6-dev
linux-image-4.9.0-3-amd64
linux-libc-dev
locales
multiarch-support
empty@testbed:~ $
EDIT: hah! testbed is still vulnerable to the Stack Clash...
Last edited by Head_on_a_Stick (2017-06-24 12:41:40)
Offline
Wow! So many nice ideas. Thank you!
I think i`ll try the first one because ...well there is sed already.
Thanks also for the tip with the -w flag.
..will mark this as solved when i have had time to test it.
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
Just to clarify: the "upgradeable" [sic] text file already has line breaks so you don't need to add them at all, just remember to always double quote the $list variable to keep these intact.
See http://mywiki.wooledge.org/Quotes for more on this.
I don't know why you're getting the output in the scrot though, that looks like the content of the "upgradeable" text file hasn't been changed at all.
Last edited by Head_on_a_Stick (2017-06-24 13:09:59)
Offline
Jeah I just played around with ponysays mentioned -W option and found the line breaks to be ok. But never the less it is good to know how to eliminate the stuff in the square brackets.
So this is solved better than i have imagined it would...
See http://mywiki.wooledge.org/Quotes for more on this.
bookmarked for reference!
Thanks again!
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
Ponysay is not in Debian but would cowsay work for this?
Real Men Use Linux
Offline
Ponysay is not in Debian
A Debian Developer has a private repository for it:
Offline
DeepDayze wrote:Ponysay is not in Debian
A Debian Developer has a private repository for it:
Oh ok thanks for that.
Real Men Use Linux
Offline
^nice tip, but it also builds very smooth from source.
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline