Linux.org User-created Helpful Shell Scripts::Meta Discussion/Chat

Fanboi

Well-Known Member
Joined
Apr 16, 2021
Messages
499
Reaction score
411
Credits
6,114
This pertains to this thread by the same name. Because this forum tends to get lost in digressions -- and full disclosure: I'm one of the biggest offenders -- I thought I'd make a space for meta chat since, as @KGIII rightfully instructed in his thread:
Other than specific questions regarding existing scripts, let's *try* to keep things on-topic.

Now what I suggest is:
If you have a question that's indirect, say, "How do I label my ssd?" when it's a copy/backup script, then @ the user here and link to his/her script with the question rather.

I think that's fair, yes? Also, I'm sure we can move the existing off-topic posts here, too. Let's try to keep that thread clean. ;)

- J
 


@captain-sensible
python is technically a scripted language can we mention those ?
what about php ?
I would imagine that perl, awk, python, ruby, etc. are all allowed within the context of what can be run as a shell script or embedded in one. I mean bash is executed within a "shell script", as are several languages/executables. I think the best way to look at it is: "Will the entire thing run in the CLI?"
 
that makes sense ,so my post on python is Ok since
Code:
[andrew@darkstar:~][1]$ which fetchmirrorsgui                             (07-26 17:01)
/usr/bin/fetchmirrorsgui
 
that makes sense ,so my post on python is Ok since
Code:
[andrew@darkstar:~][1]$ which fetchmirrorsgui                             (07-26 17:01)
/usr/bin/fetchmirrorsgui
Would imagine so.
 
This script isn't mine, I didn't write it. An acquaintance of mine wrote it for me to check for a certain nvidia driver version in Arch repo but it can be used for anything similar, if you change the URL address.

Code:
#!/bin/bash
while [ 0 -eq 0 ]
do
    CHECK="$(curl -s https://archlinux.org/packages/extra/x86_64/nvidia-dkms/ | grep '<h2>nvidia-dkms')"
    CHECK2="$(echo $CHECK | sed 's/<h2>//g' | sed 's/<\/h2>//g')"
    CHECK3="$(echo $CHECK2 | wc -m)"
    if [ $CHECK3 -ge 21 ]
    then
            echo "$CHECK2, I'll check again in a week."
    else
            zenity --info --text "NVIDIA-DKMS stable driver is available\n<b>$CHECK2</b>" --width="400" --title="NVIDIA DKMS driver check"
    fi
    sleep 604800
done

The reason I needed this script is because nvidia seems to be pushing mostly beta drivers on linux users (XXX.XX.XX) which don't support some things like NVENC. So instead of checking every week whether they have released a stable driver, I rely on the script to do the check for me and if such a driver is available, it will show me a zenity window with a message. If no stable driver is available, it will show nothing.
Initially the script was for the regular version but then I realized the DKMS edition is much more useful (bc it performs 'mkinitcpio -p linux' on its own for both linux and linux-lts), so I changed the script to check for the DKMS edition.
The way he explained it to me - the script checks if the package name has less than 21 characters. If it has less than 21, then that's a stable driver (for instance: nvidia-dkms 515.57-1). If exactly 21 or more, that's the unwanted by me beta driver (nvidia-dkms 515.65.01-1).
 
Probably way off topic, but I've been wondering so I'll ask.
Pretty new with Linux terminology yet, so here is my question .... Do I understand correctly that shell scripts are the linux version of what used to be called batch files?
 
Probably way off topic, but I've been wondering so I'll ask.
Pretty new with Linux terminology yet, so here is my question .... Do I understand correctly that shell scripts are the linux version of what used to be called batch files?
You have the right general idea... but all the stupid stuff you really hated if you ever tried to right a "non-trivial" batch script is done up right in shell scripting.

I've even gone so far as to load the cygwin system on Windows boxes just so I could write a decent script. Of course I totally went ape and loaded pretty much the -entire- cygwin system (it's huge) and have had a lot of fun with it ever since... but it still has MS Windows underneath so most of my real fun still happens on linux boxes.

BTW, "batch" files are still a thing and still quite useful at times, they're just really painful to write once you've been exposed to shell scripting.
 
Thanks for the info. While I doubt I'll be trying to write any shell scripts, or batch files for that matter, it's nice to understand the threads I come across.
 

Members online


Latest posts

Top