LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-26-2022, 09:28 PM   #16
fourtysixandtwo
Member
 
Registered: Jun 2021
Location: Alberta
Distribution: Slackware...mostly
Posts: 328

Rep: Reputation: 217Reputation: 217Reputation: 217

This thread is a great idea. Here's a few I use adapted to use the same PKGDIR variable.

Code:
PKGDIR="/var/lib/pkgtools/packages"

# list kernel pkgs natural sort
kernsort () {
  ( cd $PKGDIR ; ls -lv kernel-* )
}

# list kernel pkgs grouped by version
kernsortver () {
  ( cd $PKGDIR ; ls kernel-* ) | sort -t- -k3
}

# get list of installed slackbuilds (_SBo tag) that no longer exist in repo
SLACKBUILDS=/var/lib/sbopkg/SBo/15.0/SLACKBUILDS.TXT
#SLACKBUILDS=/usr/sbo/repo/SLACKBUILDS.TXT
#SLACKBUILDS=/var/lib/slpkg/repository/SLACKBUILDS.TXT

sbremoved () {
  for i in `( cd $PKGDIR ; ls *_SBo ) | rev |cut -d- -f4-|rev`
  do
    echo -n "$i "
    grep -c "SLACKBUILD NAME: $i$" $SLACKBUILDS
  done | grep 0$
}
 
1 members found this post helpful.
Old 12-27-2022, 04:13 AM   #17
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,057

Rep: Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349
Quote:
Originally Posted by 0XBF View Post
@pan64

The idea behind this thread was to generate some discussion around convenience functions or scripts that users have cooked up over the years to help manage, troubleshoot, or speed up any other menial tasks on their Slackware system.
It is in general a very good idea.
Quote:
Originally Posted by 0XBF View Post
These ideas are not going into the distribution, they were just talking points that I was trying to use to spark some ideas or conversation. I'm just another Slackware user and not making development decisions for anyone.
When you post them and show them (not exactly you, but anyone), it means you want to add something to slackware (but in general to any distro). it's a helpful tool, and it's meant to be useful for more than just you (oh yes, you did make development already). Which is totally fine really.
And now comes the interesting part: do you want to share low quality, slow and resource hungry code just because you don't really care about that 1 sec?
Quote:
Originally Posted by 0XBF View Post
I got your point about inefficiencies of using sub-shells so lets not beat a dead horse about perfect coding practices because that's not what I wanted to discuss.
And this is the next step: I [tried to] improve your code by discussing that issue, because I care about it. Is it a common goal, isn't it?
Quote:
Originally Posted by 0XBF View Post
If there's no interest in the topic as I originally posed in post #1 then I'm fine letting it die off without the arguing over how people should write their bash scripts. If I wanted better efficiency I would write something in C, not bash, but that's not the point here.
That is just wrong, you can write high and low quality code on any language. Obviously discussing the quality of the scripts is [almost] offtopic here, but a very important question. For my part, I would do my best if I wanted to give (share) anything to others.
 
2 members found this post helpful.
Old 12-27-2022, 04:47 AM   #18
Windu
Member
 
Registered: Aug 2021
Distribution: Arch Linux, Debian, Slackware
Posts: 597

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
That is just wrong, you can write high and low quality code on any language. Obviously discussing the quality of the scripts is [almost] offtopic here, but a very important question. For my part, I would do my best if I wanted to give (share) anything to others.
Code can be written less than optimally if that has a purpose, which is that of understanding and readability. Otherwise, everybody should just write assembler code, right? Including you.
 
Old 12-27-2022, 05:53 AM   #19
Bindestreck
Member
 
Registered: Jul 2011
Location: Sweden
Distribution: Slackware
Posts: 822

Rep: Reputation: 442Reputation: 442Reputation: 442Reputation: 442Reputation: 442
I side up with @pan64 here. Why everyone feels buttfucked when @pan64 clearly just try to give advice on how to further improve the code? Why is that bad?
 
1 members found this post helpful.
Old 12-27-2022, 06:21 AM   #20
Windu
Member
 
Registered: Aug 2021
Distribution: Arch Linux, Debian, Slackware
Posts: 597

Rep: Reputation: Disabled
Quote:
Originally Posted by Bindestreck View Post
I side up with @pan64 here. Why everyone feels buttfucked when @pan64 clearly just try to give advice on how to further improve the code? Why is that bad?
I have no issue with his suggestions for improving the example code snippets, they are good. I was triggered by his remark "Wasting resources is a bad habit. It does not hurt as long as your box has no real task to do. You can do what you want for yourself, but for such a community, this is not an example to follow".
 
1 members found this post helpful.
Old 12-27-2022, 09:44 AM   #21
0XBF
Member
 
Registered: Nov 2018
Distribution: Slackware
Posts: 799

Original Poster
Rep: Reputation: 930Reputation: 930Reputation: 930Reputation: 930Reputation: 930Reputation: 930Reputation: 930Reputation: 930
Quote:
Originally Posted by pan64 View Post
And now comes the interesting part: do you want to share low quality, slow and resource hungry code just because you don't really care about that 1 sec?
Context matters here. A scenario where I use these generally goes like this: 1. I find a library or file or something and wonder where it came from, so I 'pkggrep' it. If I want to look further at that package I 'pkgcat' into a pager and read it. Execution time doesn't matter for my case and I'm not calling the function with heavy usage from another script or anything. My aim was that it made it quicker than writing out the full "cat <full pathname>" to examine a package, and that was about it.

Quote:
Originally Posted by pan64 View Post
Obviously discussing the quality of the scripts is [almost] offtopic here...
Exactly the point I was trying to make. I wasnt trying to just talk about the most efficient way to do my pkgcat function and I didnt want the topic to get "buried in the weeds" over that. I appreciate your suggestions for improvements, but then devolving into back and fourth about wasting resources and doing things "the MS way" kinda derails the topic of getting others to share their own scripts/functions, so I was trying to nip it in the bud. I hope you understand where I'm coming from.
 
1 members found this post helpful.
Old 12-27-2022, 11:45 AM   #22
gegechris99
Senior Member
 
Registered: Oct 2005
Location: France
Distribution: Slackware 15.0 64bit
Posts: 1,162
Blog Entries: 5

Rep: Reputation: 394Reputation: 394Reputation: 394Reputation: 394
I have a script that checks for update of Slackware or third-party package repositories (I'm using slackpkg+).
The script runs every hour using cron and sends a desktop notification when the Slackware or a third-party repository has any update.
To be able to send a desktop notification (to fluxbox), I need to export the session DBUS_SESSION_BUS_ADDRESS variable before executing notify-send.
The way I get DBUS_SESSION_BUS_ADDRESS variable could probably be improved but as stated by OP, it's not the primary topic to be discussed here.
However, I'm open to suggestion (maybe in PM to avoid being off-topic).


Code:
$ crontab -l
SHELL=/bin/bash

# Check update of Slackware packages
# minute | hour | day of month | month | day of week
0 * * * * sh $HOME/data/script/check_slackware_update.sh
Code:
$ cat $HOME/data/script/check_slackware_update.sh 
#!/bin/bash
/usr/sbin/slackpkg &>/dev/null check-updates
username=$(/usr/bin/whoami)
export $(ps -u $username e | grep -m 1 -Eo 'DBUS_SESSION_BUS_ADDRESS=[^ ]* ')
[ -s ~/.slackpkg/updated-repos.txt ] && /usr/bin/notify-send -i dialog-warning "[ S L A C K P K G + ]" "Available updates in repositories: $(cat ~/.slackpkg/updated-repos.txt|tr '\n' ','|sed 's/,$//')"
 
Old 12-27-2022, 06:05 PM   #23
metaed
Member
 
Registered: Apr 2022
Location: US
Distribution: Slackware64 15.0
Posts: 375

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by gegechris99 View Post
I have a script that checks for update of Slackware or third-party package repositories
I do something similar but without notifications. I depend on cron to mail me the update. The core tool is:
Code:
#! /bin/sh
# Compiled from slackcheck.nw using Noweb by Norman Ramsey.
cd /var/lib/slackcheck
id=$(sed -n '/^ID=\(.*\)$/ s//\1/p' /etc/os-release)
case "$id" in
slackware)  server=ftp://ftp.slackware.com/pub ;;
*)      echo slackcheck: id="$id" not yet supported by slackcheck
        exit 1
esac
case $(uname -m) in
i[3456]86)     archpath=slackware/slackware ;;
[xX]86[_-]64)  archpath=slackware/slackware64 ;;
*)      echo slackcheck: $(uname -m) architecture not yet supported by slackcheck
        exit 1
esac
version=$(sed -n '/^VERSION="\(.*\)"$/ s//\1/p' /etc/os-release)
codename=$(sed -n '/^VERSION_CODENAME=\(.*\)$/ s//\1/p' /etc/os-release)
case $codename in
current) changelog=$server/$archpath-current/ChangeLog.txt ;;
stable)  changelog=$server/$archpath-$version/ChangeLog.txt ;;
*)      echo slackcheck: this /etc/os-release not yet supported by slackcheck
        exit 1
esac
wget -Nq $changelog
laststamp=` 2>/dev/null cat ChangeLog.stamp `
thisstamp=` 2>/dev/null head -1 ChangeLog.txt `
if [ "$thisstamp" = "" ]
then    echo slackcheck: failed to get timestamp
        exit 1
elif [ "$laststamp" = "" ]
then    echo 'slackcheck: first run, saving timestamp - run again later to see changes'
        >ChangeLog.stamp echo "$thisstamp"
        exit 0
elif [ "$thisstamp" = "$laststamp" ]
then    exit 0
else    sed -n " /^$laststamp/q ; /^ /d ; p " ChangeLog.txt
        >ChangeLog.stamp echo "$thisstamp"
fi
I've packaged this but haven't published the package yet. Consider this an "alpha quality" snapshot.
 
Old 12-27-2022, 08:04 PM   #24
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Trying to simplify /etc/os-release parsing...
Code:
read -r os version codename < <( grep -Po '(?<=ID=|CODENAME=).+' /etc/os-release | tr $'\n' ' ')
echo $os
echo $version
echo $codename
 
Old 12-27-2022, 09:56 PM   #25
pghvlaans
Member
 
Registered: Jan 2021
Distribution: Slackware64 {15.0,-current}, FreeBSD, stuff on QEMU
Posts: 462

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Here's a script that saves and modifies a list of man pages I want to read later:
Code:
#!/bin/ksh

LISTFILE=$HOME/.man_backlog
BKLTMP=$(mktemp /tmp/XXXX.manbklog)

case $1 in
	-h|--help)
	echo
	echo "Usage: -a: Add a man page to the list"
	echo "       -d: Remove a man page from the list"
	echo "No argument: display the list and read a page"
	echo
	exit
	;;
	-a)
	for arg in $@; do
		[ $arg != $1 ] && echo $arg >> $LISTFILE
	done
	exit
	;;
	-d)
	for arg in $@; do
		GREPCMD="$GREPCMD -e $arg"
	done
	GREPCMD="grep -vx $GREPCMD"
	$GREPCMD $LISTFILE > $BKLTMP
	mv $BKLTMP $LISTFILE
	exit
	;;
esac

if [ $(wc -l $LISTFILE | cut -d' ' -f1) -gt 0 ]; then
	echo
	echo You\'ve got at least one man page to read...
	echo
	cat $LISTFILE | sort -u
	echo
	echo Pick one...
	read PICK
	man $PICK
	echo Delete? \(y/*\)
	read YN
	if [ $YN == "y" ]; then
		grep -vx $PICK $LISTFILE > $BKLTMP
		mv $BKLTMP $LISTFILE
	fi
	echo
	exit
fi
 
Old 12-28-2022, 02:45 AM   #26
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,057

Rep: Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349Reputation: 7349
Quote:
Originally Posted by keefaz View Post
Trying to simplify /etc/os-release parsing...
Code:
read -r os version codename < <( grep -Po '(?<=ID=|CODENAME=).+' /etc/os-release | tr $'\n' ' ')
echo $os
echo $version
echo $codename
it is cryptic a bit. What about simply sourcing that file?
Code:
source /etc/os-release
echo "OS=$NAME"
echo "VERSION=$VERSION"
echo "CODENAME=$VERSION_CODENAME"
 
1 members found this post helpful.
Old 12-28-2022, 04:16 AM   #27
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by pan64 View Post
it is cryptic a bit. What about simply sourcing that file?
Code:
source /etc/os-release
echo "OS=$NAME"
echo "VERSION=$VERSION"
echo "CODENAME=$VERSION_CODENAME"
Of course !

And if you don't want to import all variables in environment
Code:
read -r os version codename < <(. /etc/os-release ; echo $ID $VERSION $VERSION_CODENAME)
 
1 members found this post helpful.
Old 12-28-2022, 11:33 AM   #28
metaed
Member
 
Registered: Apr 2022
Location: US
Distribution: Slackware64 15.0
Posts: 375

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by keefaz View Post
And if you don't want to import all variables in environment
This also has the advantage over the earlier suggestion that it isn't position dependent. It will work regardless of what order the variables appear in /etc/os-release.
 
Old 12-28-2022, 11:58 AM   #29
gus3
Member
 
Registered: Jun 2014
Distribution: Slackware
Posts: 490

Rep: Reputation: Disabled
I've used this little, Slackware-based script for years. It's an easy way to grant a temporary root privilege to a single command, and it uses only $HOME, not /etc or /usr.

Code:
#!/bin/sh
case `id -u` in
        0) # privileged script here
           ;;
        *) # wrapper here and ready
           exec /bin/su -c "`which $0`" -
           ;;
esac
Over the years, I used this to adjust the temperature and frequency of the CPU load, as well as reclaim the swap area back into RAM, whenever I wanted. It's so simple to use.

For example, unswap back into RAM:

Code:
#!/bin/sh

# 2019-11-30 MVM : Unswap in sequence, not in toto.
case `id -u` in
        0) ( for i in $(awk '/dev/ {print $1;}' < /proc/swaps) ; do
                        /sbin/swapoff $i ; /sbin/swapon -p 1 $i
                done ) ;;
        *) exec /bin/su -c "`which $0`" - ;;
esac
It can go anywhere in $HOME (I use ~/bin/), and then I add +x. Then, when I want to run it with privileges, I don't need to add "su" or "sudo" first, do something, and then... type it again because I goofed... now, password... you get it. It's very similar to normal scripting, but with the added fun of $ROOT instead of $HOME.

What about the "exec /bin/su -c..."? That's the step to "restart this, with root." And, if you already have root privileges, you don't need a password.

(too much explaining...)
 
Old 12-28-2022, 01:01 PM   #30
metaed
Member
 
Registered: Apr 2022
Location: US
Distribution: Slackware64 15.0
Posts: 375

Rep: Reputation: 173Reputation: 173
Quote:
Originally Posted by keefaz View Post
Code:
read -r os version codename < <(. /etc/os-release ; echo $ID $VERSION $VERSION_CODENAME)
I generally avoid shell extensions -- referring here to the process substitution expression <( command ). I prefer anything I write to be portable as possible. Even though my tool is so dependent on Slackware that it makes little difference, I'll still review it for portability before release.

Here's a demonstration. This solution is more readable than my original, but designed to be shell-independent. Per your suggestions, it uses the shell for parsing, employing a subshell to avoid importing unused variables.

version=` . /etc/os-release ; echo $VERSION `
codename=` . /etc/os-release ; echo $VERSION_CODENAME `


Passes Slackware 15's Bash and Korn shells, with and without -oposix. It is likely to pass even a real Bourne shell, because it uses backquotes instead of $() for command substitution.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Google's tips and tricks guide for Android users LXer Syndicated Linux News 0 07-27-2016 03:57 PM
nVidia - No diversion 'diversion of /usr/lib/xorg/modules/extensions/libglx nicolasdiogo Linux - Hardware 2 12-31-2012 08:14 AM
GNOME:(Convenience) Any way to input shell commands without bringing up a terminal? kopatops Linux - Software 6 03-13-2010 04:05 PM
LXer: Tips4Linux.com - Tips and Tricks for Linux Users LXer Syndicated Linux News 0 07-14-2009 03:30 PM
Ubuntu 5.10 -> 6.06: diversion of /usr/bin/ldd to /usr/bin/ldd.amd64 by ia32-libs HellSpawn Linux - Software 2 06-04-2006 09:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration