Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Share your Debian SCRIPTS

Here you can discuss every aspect of Debian. Note: not for support requests!
Message
Author
User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#61 Post by fabien »

updated popopop from no version to v.1.0
- better color compatibility with some terminals
- better popcon legibility
- faster unattended-upgrades function
- more unattended-upgrades messages highlighted

updated apt-fly from v.2.4 to v.3.0
- can now query alternative sources thanks to the schow-pkg framework
- it is now possible to select arbitrary packages to work on
- readline completion is now available
- several important fixes and improvements

updated schow-pkg from 4.2 to 4.3
- updated to meet apt-fly v.3.0 requirements (Contents files acquisition)
- new Bash completion function (added architectures completion)
- new -d option: allows fetching manuals and changelogs from alternative sources via debmany
- new -i option: show installed packages only
- new -U option: display alternative sources summary

updated why-pkg from v.0.8c to v.0.9a
- updated to welcome changes in upcoming Bookworm
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- virtual packages are now highlighted in search results (f_why)
- new -E option: exclude virtual packages from search results (f_why)
- new -U option: apply pin priority 990 to given suite (f_why, f_reverse)
- new -V option: display not installed dependencies vertically (f_reverse)
- added missing enhancement packages detection (f_audit)

Happy New Bookworm Year to all!

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#62 Post by fabien »

manyroads wrote: 2022-08-16 22:29The following Yad script provides a small System Monitoring panel of ncurses apps. By way of full disclosure, this script also works on arch, devuan and *buntu. :shock:
Mine has a Debian tab, so it's related to Debian :) (yes, I'm cheating with my own rule, but I'm the only one who seems to understand it, so...)

Thanks for the idea. I found it useful because I tend to forget some non-graphical applications and it helps me remember them. Six years since I had used Tcl/Tk, good exercise too.

Code: Select all

#!/usr/bin/env wish

### versatilelauncher v.1.0
### of1_À_disroot_POINT_org 2022
### Yet another launcher, but this one is versatile, whatever that means :)
###########################################################################
###########################################################################
###########################################################################


### Settings
############

### Notes: xterm does not always display well all applications \
           gnome-terminal -e is obsolete but -- doesn't work with su
#set termcmd "gnome-terminal --maximize -e"
#set termcmd "konsole --separate -e"
#set termcmd "lxterminal --geometry=[regsub -- " " [wm maxsize .] "x"] -e"
#set termcmd "xfce4-terminal --maximize -e"
set termcmd "xterm -maximized -bg black -fg white -e"

### select the iconify checkbutton on startup (true|false)
set defaultIconify "true"

### m:mandatory o:optional    m 1|m 2|m3|o 4|o 5|m6
### Category|Application name|application|prefix|options|inTerminal(Boolean)
### full path for apps not in the user PATH - unknown apps automatically discarded
### e.g. Network|netdiag netwatch|/usr/sbin/netwatch|LANG="C.UTF-8"|-e enp2s0|1
set appList {
   General|bpytop|bpytop|||1
   General|btop|btop||-p 0|1
   #General|btop|btop||-p 2|1
   General|glances|glances|||1
   General|nmon|nmon|NMON=cjJmdnt||1
   General|procmeter3|procmeter3|||0
   General|saidar|saidar||-c|1
   General|stacer|stacer|||0
   General|yacpi|yacpi||-l|1
   Processes|atop|atop|||1
   Processes|htop|htop|||1
   Processes|LXDE task manager|lxtask|||0
   Processes|Xfce4 task manager|xfce4-taskmanager|||0
   Disk usage|baobab|baobab|||0
   Disk usage|iotop|/usr/sbin/iotop|||1
   Disk usage|ncdu|ncdu||--color dark /home/|1
   Disk usage|nmon djm|nmon|NMON=djm||1
   Disk usage|xdiskusage|xdiskusage|||0
   Network|bwm-ng curses|bwm-ng|||1
   Network|bwm-ng curses2|bwm-ng||--output curses2|1
   Network|cbm|cbm|||1
   Network|ethstatus|ethstatus||-i enp2s0|1
   Network|iftop|/usr/sbin/iftop|||1
   Network|jnettop|/usr/sbin/jnettop|||1
   Network|netdiscover|/usr/sbin/netdiscover|||1
   Network|nethogs|/usr/sbin/nethogs|||1
   Network|netwatch from netdiag|/usr/sbin/netwatch||-e enp2s0|1
   Network|nload|nload|||1
   Network|pktstat|/usr/sbin/pktstat|||1
   Network|slurm|slurm||-s -i enp2s0|1
   Network|wavemon|wavemon||-i wlp1s0|1
   Debian|aptitude|aptitude|||1
   Debian|synaptic|synaptic-pkexec|||0
   Debian|popopop popularity-contest|popopop|||1
   Debian|popopop unattended-upgrades|popopop||-u|1
   Debian|apt-fly|apt-fly|||1
   Debian|schow-pkg|schow-pkg|||1
   Debian|why-pkg|why-pkg|||1
   #New category|New name|newapp|||1
}
### /Settings
##############



proc f_simpleErrMsg {msg dtl {quit "1"}} {
   wm withdraw .
   tk_messageBox -icon error -message "[file tail $::argv0]:\n$msg" -detail $dtl
   if {$quit} {exit} else {wm state . normal}
}


if {![llength [auto_execok [lindex $termcmd 0]]]} {
   f_simpleErrMsg "wrong terminal “[lindex $termcmd 0]”:" "please set a working terminal"
}


set appList [split $appList "\n"]
foreach line $appList {
   if {[string length [string trim $line]] < 9 || [string match {#} [string index [string trimleft $line] 0]]} {continue}
   if {![string match {|[01]} [string range [string trim $line] end-1 end]]} {f_simpleErrMsg "wrong appList line (Err1):" $line}
   set line [split [string trim $line] "|"]
   if {[llength $line] != 6} {f_simpleErrMsg "wrong appList line (Err2):" $line}
   if {[string is space [lindex $line 0]] || [string is space [lindex $line 1]] ||
       [string is space [lindex $line 2]]} {f_simpleErrMsg "wrong appList line (Err3):" $line}
   dict set appsDict [lindex $line 0] [lindex $line 1] "{[lindex $line 2]} {[lindex $line 3]} {[lindex $line 4]} {[lindex $line 5]}"
}
unset appList line



###Application|Prefix|Options|inTerminal(Boolean) suTriState
proc f_launch {app pfx opt trm su3state} {
   if {$::editState && !$::fromLaunchBT} {
      if {!$su3state} {.f3.fOpts.suCB deselect; .f3.fOpts.suCB configure -fg black}
      .f3.fEdit.editEN delete 0 end
      .f3.fEdit.editEN configure -foreground black
      .f3.fEdit.editEN configure -textvariable $trm
      .f3.fEdit.editEN insert 0 [string trim "$pfx $app $opt"]
      return
   }
   if {$::fromLaunchBT} {
      set ::fromLaunchBT 0
      set app [.f3.fEdit.editEN get]
      set trm [.f3.fEdit.editEN cget -textvariable]
      if {![string match {[01]} $trm] || [string is space $app]} {return}
   }
   if {$::suState} {
      .f3.fOpts.suCB deselect; .f3.fOpts.suCB configure -fg black
      if {$trm} {
         set cmdline "su --login root --command='/usr/bin/env $pfx $app $opt'"
      } else {
         f_simpleErrMsg "I'm versatile, but not to this extent." "please do not run graphical applications as root" 0
         return
      }
   } else {
      set cmdline "/usr/bin/env $pfx $app $opt"
   }
   if {$trm} {exec {*}$::termcmd $cmdline &} else {exec {*}$cmdline &}
   if {$::iconifyState} {wm iconify .}
}


proc f_gridAppsNB {} {
   foreach cat [dict keys $::appsDict] {
      incr catNbr; set appNbr -1
      ttk::frame .f2.appsNB.cat$catNbr
      .f2.appsNB add .f2.appsNB.cat$catNbr -text $cat
      grid columnconfigure .f2.appsNB.cat$catNbr 0 -weight 1
      ###Application|Prefix|Options|inTerminal(Boolean)
      foreach {appName conf} [dict get $::appsDict $cat] {
         if {![llength [auto_execok [lindex $conf 0]]]} {continue}
         if {![llength [auto_execok [file tail [lindex $conf 0]]]] && [regexp -- "/sbin/" [lindex $conf 0]]} {
            set fg red
         } else {
            if {[lindex $conf 3]} {set fg DarkOrange1} else {set fg DarkGoldenrod1}
         }
         incr appNbr
         if {$fg == {red}} {
            button .f2.appsNB.cat$catNbr.appBT$appNbr -text $appName -relief solid -background "#333" -foreground $fg \
                   -command ".f3.fOpts.suCB configure -fg red; .f3.fOpts.suCB select; f_launch $conf 1"
         } else {
            button .f2.appsNB.cat$catNbr.appBT$appNbr -text $appName -relief solid -background "#333" -foreground $fg \
                   -command "f_launch $conf 0"
         }
         grid .f2.appsNB.cat$catNbr.appBT$appNbr -row $appNbr -column 0 -pady 2
      }
   }
}


proc f_resizeNBbuttons {} {
   set newSize [expr {([winfo width [.f2.appsNB select]] - 60) / $::FixedFontPxl}]
   foreach {tab} [.f2.appsNB tabs] {
      foreach {btn} [winfo children $tab] {
         $btn configure -width $newSize
      }
   }
}


proc f_gridEdit {} {
   if {$::editState} {
      .f3.fEdit.editEN configure -width [expr {([winfo width [.f2.appsNB select]] - [winfo width .f3.fOpts]) / $::FixedFontPxl}]
      grid .f3.fEdit
   } else {.f3.fEdit.editEN delete 0 end; grid remove .f3.fEdit}
}


proc f_suCBcolor {} {
   if {$::suState} {.f3.fOpts.suCB configure -fg red} else {.f3.fOpts.suCB configure -fg black}
}



### icon (man 1 base64)
set vlIconB64 {
iVBORw0KGgoAAAANSUhEUgAAABcAAAAgCAYAAAD5VeO1AAAACXBIWXMAAC4jAAAuIwF4pT92AAAEm0lEQVRIx62VT2wUVRzHv783b/50d
rtdlsoK7UEKreGgNaxFCzZVixdtohYbTPBgohgD6sVoYgAvXowQEy8EvIg3EknQeNBQe5BgNhq9eDAVitqkGGq37Cxud3d2Zt7Pw+xud8
tsC+rbncNkZj7vve/v+74/ZDKZE+Pj4xvxP46bZ1/aXD4zfpIGBgbmdV33EonEwWw2+81/BZdOPf2sUbl6EoZWFQDguu49uVzuq0wmc2L
fvn2xfwMtfHKoq3J89GPL+fmcCG7cDYBF/SEzy0Kh8ObMzMx3IyMjO+8EXDw+MWL/kf3BXP79IJTfYIrVLwZBMFipVC4NDQ29NTExoa8F
XfjoNat05In3OhZnpjUvPwAAIAbCPwkAICIQEWzbRnd3N5aXlzscx/lgdnb2wt69e7dGynBs/47kbz99a92cO0rs6gChftV/gogAAPF4H
F1dXcjlcvA8DwBQLpcfvXbt2o+Tk5PbWsBHXrjPvn7le93N72rgaAUeXoAkIiQSCViWhaWlJTAzhFhRSymVUkolm+G6W9koAreTNKptnk
MgCRDVBCGC3LRpE5gZuVwuLIJoLQMzR4jCICHAggChAAGQIEAEAAkoKeF1JJUsFovwfR+6rt8CJCIopW5BEwAICWgMaKo2gQKEFk7ACrL
skAQAwzDaOiJq5QoAdAOkA9AVWDJYBiCpoIQPCgogjkGaprkmvHmxKzcEmDbYBMhQIF2BDUZAVWhVB2yEu5XxeCcsq6MtNQj86Ad2AmRS
CBIeuPIXRJBrgAFAJpNJdHZ2toV7XhWlUqlFGxYCSGyEkgwuL4BuzoG0EshgMAH1ksl0Oo1Uqn0ouq6L2dnLrRoxQ93IwVcFSD8PIVyw1
uQkAhQIkplhx2zYtg3DMCE12XCJ73twCs6tRdZ1BMUF6P4NCOECVlSRGHJq6gKUUg1/EwlomgbP88Ac6jc4OLja5ZClAoTmRqRTk3pNJx
FKKQSBj2rVbYABIJ/P39v8lVgu7CDfBdfOZjuHyduJ1Pn5+U8zmczg+w8OfPiIv/iusTT3KmRoSVWLwFVbC91yO3CllCwUCm9j9pfD5gY
Vgxk0KGGycD1dAKb6qWCxHljKlfnJ92MUoUM9EQOIMM/bNYuI5rHuzrgBUy0SrQuPTsVVYGYQuKYGhdIAEETUsrRYLIZUKrXOGlcsuSJL
44QBYCiQEul0+nnTNC8DQCqVgmVZyOfzbfNLUZM7mFsTrfZOoN/1q9fVf0BcvHgxu3379l09PT2nhRCq3o3aDcEAa7LWdVbti3RV7dh2u
tw7+lDswGfZlsfDw8PPOI5z0vO8zVHgUz0mHu8mwFSAoQAzAOkAWwqB3fmn1731kP3G+S8iC5rNZj/v7e3dGY/HzxNRdHsDtaS7ImLP2n
KumH5gZzM40i1TU1PX9+zZ81wqlXpFSllYo2dAabZT6ep/uXj/U/s3HD6zsGaHWT3Gxsb6FxcXz5RKpd11Wca6BdhS8BIbLpW39L6YPHb
2atv6rAWfnp6+0tfX91gymTyqaZoLAIGmVyqJ3necHcNja4HvaIyOjj789ZO7v/z79cmh2/3mH2CK4OWi38F+AAAAAElFTkSuQmCC}
image create photo vlIcon -data $vlIconB64; unset vlIconB64


### widgets
ttk::frame .f1
ttk::frame .f1.fTitle
label .f1.fTitle.iconLB -image vlIcon
label .f1.fTitle.titleLB -text "VersatileLauncher" -font {-size 14 -slant italic -underline 1} -fg "#222"
button .f1.exitBT -text "Quit" -relief raised -command "destroy .; exit"

ttk::frame .f2
ttk::notebook .f2.appsNB

ttk::frame .f3
ttk::frame .f3.fOpts
checkbutton .f3.fOpts.iconifyCB -text iconify -variable iconifyState
checkbutton .f3.fOpts.suCB -text root -variable suState -command f_suCBcolor
checkbutton .f3.fOpts.editCB -text edit -variable editState -command f_gridEdit
ttk::frame .f3.fEdit
ttk::entry .f3.fEdit.editEN -foreground red -textvariable termValue -font TkFixedFont
button .f3.fEdit.launchBT -text "Launch" -relief raised \
       -command "set fromLaunchBT 1; f_launch {} {} {} {} 2"


### widgets grid
grid .f1                                  -row 0 -column 0              -sticky news -padx 5 -pady 3
   grid .f1.fTitle                           -row 0 -column 0           -sticky nws
      grid .f1.fTitle.iconLB                    -row 0 -column 0
      grid .f1.fTitle.titleLB                   -row 0 -column 1
   grid .f1.exitBT                           -row 0 -column 1           -sticky nes

grid .f2                                  -row 1 -column 0              -sticky news -padx 5 -pady 2
   grid .f2.appsNB                           -row 0 -column 0           -sticky news -ipady 2
   f_gridAppsNB

grid .f3                                  -row 2 -column 0              -sticky news
   grid .f3.fOpts                            -row 0 -column 0           -sticky w
      grid .f3.fOpts.iconifyCB                  -row 0 -column 0        -sticky w
      grid .f3.fOpts.suCB                       -row 1 -column 0        -sticky w
      grid .f3.fOpts.editCB                     -row 2 -column 0        -sticky w
   grid .f3.fEdit                            -row 0 -column 1           -sticky ews
      grid .f3.fEdit.launchBT                   -row 0 -column 0        -sticky se
      grid .f3.fEdit.editEN                     -row 1 -column 0        -sticky sw


grid columnconfigure . 0 -weight 1
grid columnconfigure .f1 0 -weight 1
grid columnconfigure .f2 0 -weight 1
grid columnconfigure .f3 0 -weight 1
grid columnconfigure .f3.fEdit 0 -weight 1

grid rowconfigure . 1 -weight 1
grid rowconfigure .f2 0 -weight 1

bind . <Configure> {
   f_resizeNBbuttons
   .f3.fEdit.editEN configure -width [expr {([winfo width [.f2.appsNB select]] - [winfo width .f3.fOpts]) / $::FixedFontPxl}]
}


### init state
set fromLaunchBT 0
set FixedFontPxl [font measure TkFixedFont -displayof .f3.fEdit.editEN a]
if {$defaultIconify} {.f3.fOpts.iconifyCB select}
.f3.fEdit.editEN insert 0 "command line, be cautious"
grid remove .f3.fEdit
wm title . "Versatile Launcher"
wm iconphoto . -default vlIcon
wm withdraw . ; wm state . normal ;##useful with some WM
update; wm minsize . [winfo width .] [winfo height .]
f_resizeNBbuttons

### md5sum/shasum - script's last line ### versatilelauncher v.1.0 ###
Attachments
VersatileLauncher
VersatileLauncher
versatilelauncher.png (91.16 KiB) Viewed 17520 times

User avatar
manyroads
Posts: 73
Joined: 2021-04-17 14:27
Has thanked: 1 time
Been thanked: 13 times

Re: Share your Debian SCRIPTS

#63 Post by manyroads »

Very nice.
Pax vobiscum,
Mark Rabideau- Prof Genealogist - http://many-roads.com
Linux BLOG https://eirenicon.org
spectrwm,SwayWM,i3wm,hlwm,bspwm,dwm on sid
Linux User #449130

User avatar
Zoot
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 163
Joined: 2010-01-12 15:27
Location: Ireland
Has thanked: 5 times
Been thanked: 3 times

Re: Share your Debian SCRIPTS

#64 Post by Zoot »

When I was having the issue with one of the drives dropping offline randomly in my server, I came up with this script to notify me if this was to happen. This is the thread BTW - viewtopic.php?t=153685

It checks the following for all mounted filesystems:
  • Are they all present? (None have dropped offline)
  • Is there filesystem errors on any of them? (Maybe something has gone wrong causing filesystem errors, which did happen to me)
  • Have any of them been remounted read-only? (The default behaviour is re-mount filesystems read-only if errors are detected)
  • Are any of them full (>95%) ?
If any of the above are found to be true, it'll send a notification email as to what the problem is.

This was useful for me to run on a schedule via an hourly basis, as I generally didn't know that a drive dropped offline until a subsequent sync or scrub of my storage array would fail which could be 12+ hours later with the way I have it scheduled.

If anyone wants to use it, it requires a change on line 15 for the number of expected filesystems present, mutt for sending emails, a valid muttrc file, and an email address. I don't consider myself a scripting expert, so there certainly could be a better way of doing this, but this is a way that has worked for me.

Code: Select all

#!/bin/bash
######################################
# Filesystem Check Script
######################################
# Performs a Number of Checks on all Mounted Filesystems
# 1 - Checks to see if the expected amount of Filesystems are Mounted
# 2 - Checks to see if filesystem errors have been detected on any of the Filesystems
# 3 - Checks to see if any of the filesystems have been mounted read-only
# 4 - Checks to see if any of the filesystems are full (In This Case >95% Full)
# An Email will be sent if an error is detected, whereas a success email will only be
# send once a week. The reason for this is that this script is intended to be ran hourly.
######################################

# Expected Number of Mounted Partitions
expected_number_of_mounted_partitions=13

# Input Variables
percent_full_threshold=95

# Next, find what the current time & date are to Create a Log File
start_time=`date '+%Y-%m-%d_%H-%M-%S'`
start_seconds=$(date +%s)

# Determine Day & Hour of Day to Send Success Email of Not
weekday=$(date | awk '{print $1}')
time_now=$(date | awk '{print $4}')
hour_now=${time_now:0:2}

# Logfile Directory (Usually /tmp is best)
logfile_directory=/tmp/

# Email Address
email_address="xxxxx@yyyyy.com"

# Mutt Config File Location
# Required if read/write access to /home
# is restricted
muttrc_path=/Appdata/mutt/muttrc

# Define the necessary logfiles for analysis,
# For some stupid reason in the below
# loop the full_count and error_count get reset
# to zero after the loop has finished. There's
# probably an obvious problem, but the easy
# and messy solution is to dump their output into
# files also, and read them after the loop is finished.
logfile=$logfile_directory'filesystem_check_log_'$start_time'.log'
full_count_file=$logfile_directory'filesystem_full_check_count_'$start_time'.log'
error_count_file=$logfile_directory'filesystem_error_check_count_'$start_time'.log'
readonly_count_file=$logfile_directory'filesystem_readonly_check_count_'$start_time'.log'

# First - Check for Root
if [ $UID != 0 ]
then
        echo "Script must be ran as root... Exiting..."
        exit 1
fi

# Full Count
full_count=0
echo 0 > $full_count_file

# Error Count
error_count=0
echo 0 > $error_count_file

# Read-Only Mounted Count
readonly_count=0
echo 0 > $readonly_count_file

# Number of Mounts Error
no_of_mounts_error=0

# Prepare Logfile
echo "Filesystem check performed at" $start_time", the output is below:" > $logfile
echo "" >> $logfile
echo -e "Filesystem"'\t'"Permissions"'\t'"Errors"'\t'"Full(%)"'\t'"Mount-Point" >> $logfile

# Use df -h to check for the Number of partitions Mounted, If this is below the expected
# amount of partitions, clearly something has gone wrong
number_of_mounted_partitions=$(df -h | grep -vE '^Filesystem|none|cdrom|udev|tmpfs|Server7-Media|boot' | awk '{print $1}' | wc -l )

if [ $number_of_mounted_partitions -lt $expected_number_of_mounted_partitions ]
then
	no_of_mounts_error=1
else
	no_of_mounts_error=0
fi

# Call "df -h" and step through output to find the mountpoint,
# the parition name and the amount by which it is full. This needs
# to be done this way as there is no guarantee /dev/sda will refer
# to the same partition after a reboot.
df -h | grep -vE '^Filesystem|none|cdrom|udev|tmpfs|boot' | awk '{ print $1 " " $6 " " $5 }' | while read output;
do
	partition=$(echo $output | awk '{print $1}')
	mount_point=$(echo $output | awk '{print $2}')
	percent_full=$(echo $output | awk '{print $3}' | tr -d "%")
	filesystem_status=$(tune2fs -l $partition | grep "Filesystem state:" | awk '{print $3}')
	mount_options=$(cat /proc/mounts | grep $mount_point | awk '{print $4}')
	permissions=${mount_options:0:2}

    # Print the Output into a File for the Notification Email
    echo -e $partition'\t'$permissions'\t\t'$filesystem_status'\t'$percent_full'\t'$mount_point >> $logfile

	# Check if the partition is More Full than the threshold
	if [ $percent_full -gt $percent_full_threshold ]
	then
		full_count=$((full_count+1))
		echo $full_count > $full_count_file
	fi

	# Check if Errors have been detected on the Filesystem
	if [ $filesystem_status != "clean" ]
	then
		error_count=$((error_count+1))
		echo $error_count > $error_count_file
	fi

	# Check if the Partition has been Mounted Read-Only
	if [ $permissions != "rw" ]
	then
		readonly_count=$((readonly_count+1))
		echo $readonly_count > $readonly_count_file
	fi
done

# Retrieve Error & Full Counts from Log File
final_full_count=$(cat $full_count_file)
final_error_count=$(cat $error_count_file)
final_readonly_count=$(cat $readonly_count_file)

# Append both to the bottom of the Logfile for Email
echo "" >> $logfile
echo "Expected Number of Filesystems:" $expected_number_of_mounted_partitions >> $logfile
echo "Filesystems Present:" $number_of_mounted_partitions >> $logfile
echo "Full Filesystems:" $final_full_count >> $logfile
echo "Filesystems with Errors:" $final_error_count >> $logfile
echo "Filesystems mounted Read-Only:" $final_readonly_count >> $logfile

# Output the Logfile, so that it will show up in the journalctl logs
cat $logfile
echo ""

#############################
# Check for Detected Errors
#############################
# Investigate the value of each of the Error variables set above.
# The Email Subject is narrowed down a bit based on what combination
# is present, the email is then sent and the script will exit.

# 1 - No Errors Are Found, All Error Check Variables are Zero
if [ $no_of_mounts_error -eq 0 ] && [ $final_full_count -eq 0 ] && [ $final_error_count -eq 0 ] && [ $final_readonly_count -eq 0 ]
then
	email_subject="Filesystem Check: No Issues Found"
	echo $email_subject

	# Check for the Right Time to Send the Success Email
	if [ $weekday == "Fri" ] && [ $hour_now == "15" ]
	then
		mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

		# Check if the Email Sent Successfully for the Journalctl Logs
		if [ $? -eq 0 ]
		then
			echo "Notification Email sent successfully..."
		else
			echo "Problem sending Notification Email..."
		fi
	fi

	# Exit with Status 0 to Flag Success
	exit 0

# 2 - The Number of Filesystems detected is LESS than expected, maybe
# the disk has dropped offline due to a power outage or something else.
# Everything else is OK.
elif [ $no_of_mounts_error -gt 0 ] && [ $final_full_count -eq 0 ] && [ $final_error_count -eq 0 ] && [ $final_readonly_count -eq 0 ]
then
        email_subject="Filesystem Check: One or More Volumes NOT Present"
        echo $email_subject
	mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

        # Check if the Email Sent Successfully for the Journalctl Logs
        if [ $? -eq 0 ]
        then
		echo "Notification Email sent successfully..."
	else
		echo "Problem sending Notification Email..."
	fi

	# Exit with Status 1 to Flag an Error
	exit 1

# 3 - One or More Disks is Full, Everything else is OK
elif [ $no_of_mounts_error -eq 0 ] && [ $final_full_count -gt 0 ] && [ $final_error_count -eq 0 ] && [ $final_readonly_count -eq 0 ]
then
        email_subject="Filesystem Check: One or More Volumes Almost Full"
        echo $email_subject
	mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

	# Check if the Email Sent Successfully for the Journalctl Logs
        if [ $? -eq 0 ]
        then
                echo "Notification Email sent successfully..."
        else
                echo "Problem sending Notification Email..."
        fi

	# Exit with Status 1 to Flag an Error
	exit 1

# 4 - Errors detected on One or More Disks, Everything else OK
elif [ $no_of_mounts_error -eq 0 ] && [ $final_full_count -eq 0 ] && [ $final_error_count -gt 0 ] && [ $final_readonly_count -eq 0 ]
then
        email_subject="Filesystem Check: fsck Requied on One or More Volumes"
        echo $email_subject
	mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

	# Exit with Status 1 to Flag an Error
	exit 1

# 5 - One or More of the Volumes has been mounted Read-Only. If Errors are detected, this is often done.
# Everything else is OK.
elif [ $no_of_mounts_error -eq 0 ] && [ $final_full_count -eq 0 ] && [ $final_error_count -eq 0 ] && [ $final_readonly_count -gt 0 ]
then
        email_subject="Filesystem Check: One or More of the Disks Re-Mounted Read-Only"
        echo $email_subject
	mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

        # Check if the Email Sent Successfully for the Journalctl Logs
        if [ $? -eq 0 ]
        then
                echo "Notification Email sent successfully..."
        else
                echo "Problem sending Notification Email..."
        fi

	# Exit with Status 1 to Flag an Error
	exit 1

# 6 - Any of the Error Check Variables are Greater than Zero an Error Has Been Found
else
	email_subject="Filesystem Check: Multiple Issue Found"
	echo $email_subject
	mutt -F $muttrc_path -s "$email_subject" $email_address < $logfile

        # Check if the Email Sent Successfully for the Journalctl Logs
        if [ $? -eq 0 ]
        then
                echo "Notification Email sent successfully..."
        else
                echo "Problem sending Notification Email..."
        fi

	# Exit with Status 1 to Flag an Error
	exit 1

fi

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Share your Debian SCRIPTS

#65 Post by Hallvor »

Here is a simple update script for Debian stable that should be run with anacron. If the kernel has been updated, it shows a kdialog message box to the user to restart the system when conventient. Finally, it cleans up the downloaded package files using the "apt autoclean" command.

Note: kdialog is run as user hallvor, so you may want to change that to your username. Secondly, if you don't use KDE, zenity is a different option.

Code: Select all

#!/bin/bash

current_kernel=$(uname -r | cut -d'-' -f1)

if su -c "apt update && apt upgrade -y" && \
   new_kernel=$(dpkg -l linux-image-*.* | awk '/^ii/{print $2}' | grep -v -e "$(uname -r | cut -f1,2 -d'-')" | grep -e [0-9] | cut -d'-' -f3) && \
   [[ $current_kernel != $new_kernel ]]; then
  su - hallvor -c "DISPLAY=:0 kdialog --msgbox 'The kernel is updated. Reboot when convenient.'"
fi

su -c "apt autoclean"
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

CwF
Global Moderator
Global Moderator
Posts: 2625
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 190 times

Re: Share your Debian SCRIPTS

#66 Post by CwF »

fabien wrote: 2023-01-16 22:45 Six years since I had used Tcl/Tk, good exercise too.
Thanks for the example.
I suck at making such unified things and am frustrated with the limited zenity and yad, and I lean on gxmessage with excessively long sequences of user interaction. I'm 'tickled' with this possibility! Tcl/Tk is ancient and also current it seems, I shall learn!

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#67 Post by fabien »

CwF wrote: 2023-02-07 16:10Thanks for the example. [...] I'm 'tickled' with this possibility! Tcl/Tk is ancient and also current it seems, I shall learn!
It makes me really happy to read this as it is one of the main reasons for this topic. Tcl/Tk is long gone the hype thing it used to be but it works great, it's beginner friendly but fast and quite powerful. It's also very well documented. I would advise you to play a little with a tutorial to start: this Tcl-Tk - Quick Guide is very good because it gives all the basics of both Tcl and Tk, then you learn with a real case.

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1387
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 64 times

Re: Share your Debian SCRIPTS

#68 Post by None1975 »

fabien wrote: 2023-02-07 23:11 I would advise you to play a little with a tutorial to start: this Tcl-Tk - Quick Guide is very good because it gives all the basics of both Tcl and Tk, then you learn with a real case.
Hello. The link doesn't work (:
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#69 Post by fabien »

None1975 wrote: 2023-02-08 12:29Hello. The link doesn't work (:
The link was working yesterday! Today SEC_ERROR_REVOKED_CERTIFICATE, which will probably be fixed soon.
Still works without https http://www.tutorialspoint.com/tcl-tk/tc ... _guide.htm

CwF
Global Moderator
Global Moderator
Posts: 2625
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 190 times

Re: Share your Debian SCRIPTS

#70 Post by CwF »

fabien wrote: 2023-02-07 23:11... Tcl/Tk is long gone the hype thing it used to be but it works great, it's beginner friendly but fast and quite powerful. It's also very well documented. I would advise you to play a little...
I did find https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

I'm all hyped out, no more hype. It seems not abandoned in any way, mature, and not the typical moving target that will allude me forever. I pass through things like this to get something done, and often don't learn. I pick up enough to self-navigate but fluency is a dream.

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1387
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 64 times

Re: Share your Debian SCRIPTS

#71 Post by None1975 »

fabien wrote: 2023-02-08 12:48 Still works without https http://www.tutorialspoint.com/tcl-tk/tc ... _guide.htm
No, the link is not working.

Image
Thank you.
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Share your Debian SCRIPTS

#72 Post by Hallvor »

None1975 wrote: 2023-02-09 12:44 No, the link is not working.
It works here.
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
None1975
df -h | participant
df -h | participant
Posts: 1387
Joined: 2015-11-29 18:23
Location: Russia, Kaliningrad
Has thanked: 45 times
Been thanked: 64 times

Re: Share your Debian SCRIPTS

#73 Post by None1975 »

Hallvor wrote: 2023-02-09 13:02
None1975 wrote: 2023-02-09 12:44 No, the link is not working.
It works here.
No. It is works in chromium, but in Firefox no.

Image
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Share your Debian SCRIPTS

#74 Post by Hallvor »

Strange. I only use Firefox.

Image
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

CwF
Global Moderator
Global Moderator
Posts: 2625
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 190 times

Re: Share your Debian SCRIPTS

#75 Post by CwF »

@fabien
So far so good! I managed to change up the icon, named it MementoLauncher, revamped the applist...
I'm in a productive stumble!
That su3state is woven in there pretty tightly and I keep blowing it up trying to revamp it to a simpler way.
I'm attempting to add to f1 a checkbox for xfce4-terminal focused options; --drop-down, --tab, and the su replacement 'pkexec xfce4-termianl' I'll try my best to preserve the coloring and auto select goodness of the su3state, but I am swimming.

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Share your Debian SCRIPTS

#76 Post by Hallvor »

Here is a script to write ISO images to USB drive or SD card:

Usage:
Start the script with the path to the downloaded ISO, enter the device you want to install the ISO to. Enter the root password when prompted.

Example:

Code: Select all

hallvor@debian-mini:~$ ./.liveusb.sh ~/Nedlastingar/debian-11.6.0-amd64-netinst.iso
Available block devices:
1. sda  931,5G
2. sdb  7,5G
3. zram0        256M
Enter the device to write the ISO to (e.g. /dev/sdb): /dev/sdb
Warning: This will erase all data on /dev/sdb. Are you sure you want to continue? [y/N] y
Please enter the root password to continue:
398458880 byte (398 MB, 380 MiB) kopiert, 39 s, 10,2 MB/s
97+0 oppføringer inn
97+0 oppføringer ut
406847488 byte (407 MB, 388 MiB) kopiert, 39,9797 s, 10,2 MB/s
Passord: Passord: Done.
hallvor@debian-mini:~$ 
And here is the code:

Code: Select all

#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo "Usage: $0 <path/to/iso>"
    echo "Example: $0 ~/Downloads/debian.iso"
    exit 1
fi

iso=$1

echo "Available block devices:"
lsblk -d -n -o NAME,SIZE | awk '{print NR ". " $1 "\t" $2}'

read -p "Enter the device to write the ISO to (e.g. /dev/sdb): " device

read -p "Warning: This will erase all data on $device. Are you sure you want to continue? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    umount $device* >/dev/null 2>&1
    echo "Please enter the root password to continue:"
    read -s password
    su -c "dd if=$iso of=$device bs=4M status=progress oflag=sync" <<< "$password"
    su -c "umount $device* >/dev/null 2>&1" <<< "$password"
    su -c "sync" <<< "$password"
    echo "Done."
else
    echo "Aborted."
fi
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
Uptorn
Posts: 205
Joined: 2022-01-22 01:07
Has thanked: 171 times
Been thanked: 43 times

Re: Share your Debian SCRIPTS

#77 Post by Uptorn »

fabien wrote: 2022-04-09 15:30 why-pkg
unfortunately, due to limitations, this script cannot be pasted here
disroot pastebin
Disroot pastebin requires a whole lot of moving parts

Code: Select all

 Error decompressing paste, due to missing WebAssembly support.
Is your project hosted anywhere else?

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#78 Post by fabien »

Uptorn wrote: 2023-04-22 16:16 Disroot pastebin requires a whole lot of moving parts

Code: Select all

 Error decompressing paste, due to missing WebAssembly support.
It works for me, maybe a transient problem? Disroot is maintained by volunteers, the service is very good but they don't have the means of Big Tech.
Uptorn wrote: 2023-04-22 16:16Is your project hosted anywhere else?
Not in text form (too big for the Debian pastebin), but look at the following post, you can download a tar.gz of the four scripts.

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2020
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 138 times
Been thanked: 204 times

Re: Share your Debian SCRIPTS

#79 Post by Hallvor »

A very simple mortgage calculator. The last two lines are there to make you cry ;)

Code: Select all

#!/bin/bash

# Input prompt
read -p "Loan size: " loanSize
read -p "Yearly interest rate (%): " interestRate
read -p "Years of downpayment: " downpaymentYears

# Calculations
monthlyInterestRate=$(echo "scale=10; $interestRate/12/100" | bc -l)
downpaymentMonths=$((downpaymentYears * 12))

downpaymentPerMonth=$(echo "scale=2; $loanSize * $monthlyInterestRate / (1 - (1 + $monthlyInterestRate)^(-$downpaymentMonths))" | bc -l)

echo "Downpayment per month: $downpaymentPerMonth"

totalAmountPaid=$(echo "scale=2; $downpaymentPerMonth * $downpaymentMonths" | bc -l)
echo "Total amount paid: $totalAmountPaid"
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
fabien
Forum Helper
Forum Helper
Posts: 604
Joined: 2019-12-03 12:51
Location: Anarres (Toulouse, France actually)
Has thanked: 60 times
Been thanked: 141 times

Re: Share your Debian SCRIPTS

#80 Post by fabien »

I should have made an intermediate release. I was really planning to do this in July, for the release of Bookworm 12.1. And I thought I would be ready for the release of Bookworm 12.2. But here we are.
If you notice a bug, or have a doubt, or even just a question, don't hesitate to PM me (or use the email at the top of the scripts), it will benefit everyone. Also, if my English hurts your eyes every time you run my scripts, or if you just think some expressions could be rephrased, I'll be happy to correct them.
I hope you will enjoy my new versions. Lots of new features in schow-pkg, why-pkg not bad either.

updated popopop from v.1.0 to v.1.1
- slight code improvement

updated apt-fly from v.3.0 to v.3.1
- licensed under GPLv3+
- some improvements and edge case fixes
- can now query "All available sources" (can be memory exacting)

updated schow-pkg from 4.3 to 5.0
- licensed under GPLv3+
- now allows compound short options (e.g. -fSiv instead of -f -S -i -v)
- now supports ASCII-armored format keys (.asc) and allows ReleaseInfoChange
- it is now possible to deactivate/reactivate each of the alternative sources using -U=ID[,ID]
- there is a new cache that speeds up downloadable versions display (-v) (CUSTOMDIR must exist)
- the "All available sources" environment has been greatly improved
- new search capabilities (learn more using the -D option)
- new -b option: fetches packages vulnerabilities from security-tracker.debian.org
- new -D option: displays some documentation
- new -p option: allows arguments to be treated as apt-patterns (man 7 apt-patterns)
- new -q option: searches the binary packages that match the given source package names
- new -r option: searches the source packages that match the given binary package names
- new -R option: show source packages (apt-cache showsrc support)
- new -w option: lists downloadable package versions in remote repositories

updated why-pkg from v.0.9a to v.0.10a
- cleanup and improvement of some parts of the code, some fixes too
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- new -A option: display aptitude search patterns (f_why)
- new -M option: query alternative sources among those provided by schow-pkg (f_why, f_reverse)
- new -P option: display colored output of apt-rdepends recursive reverse dependency listings (f_why)
- new -X option: like -x, but outlines the reasons for the checks and points the way for further study (f_audit)

Post Reply