Changes

From Amahi Wiki
Jump to: navigation, search
2,786 bytes added ,  15:37, 17 June 2020
no edit summary
image =Warning.png|
heading =WARNING|
message = This is recommended only for advanced users, proceed with caution.}}The scripts below are now included in the Amahi [https://www.amahi.org/apps/terminal-scripts Terminal Scripts] application. You might also find [https://www.amahi.org/apps/shellcheck ShellCheck] helpful when developing scripts. 
Use of script files provides many useful results. Below is a small collection that should enhance your command line experience.
== README1ST ==<b><u>Terminal Scripts Application README FILE</u></b> The following scripts are included:* automysqlbackup: Backup multiple MySQL databases on a given schedule.* diskspace: Displays graphical depiction of all drive space used and remaining.* dnflog: Shows latest Fedora updates that have been applied.* dsalert: Sends email if a disk has used a set percentage of space. Requires the system have outgoing email capability. * folderspace: Displays how much space a specific folder occupies.* hdaupdates: Shows latest Amahi updates to your HDA.* smartchk: Provides health status of disks drives set in the script.* systeminfo: Displays various criteria about the system, to include host name, IP address, uptime, etc.* weather: Shows weather for a given location as preset in the script.  ALL the above scripts may require some modification for your system. * systeminfo and weather script has a variable that must be changed for your geographical area.* smartchk requires modification to list all mounted hard disk drives in your system.* automysqlbackup has various settings will need adjusted for your system. See the [[https://wiki.amahi.org/index.php/Database_Backup:automysqlbackup]] page for details.  <b><u>Dependencies Installed for Scripts</u></b> * sysinfo: pciutils and procinfo * smartchk: smartmontools * dsalert: smartmontools   <b><u>dos2unix (installed with this application)</u></b> What is it? <blockquote>dos2unix is a tool to convert text files from DOS line endings (carriage return + line feed) to Unix line endings (line feed). It is also capable of conversion between UTF-16 to UTF-8. Invoking the unix2dos command can be used to convert from Unix to DOS. This tool comes in handy when sharing files between Windows and Linux machines. </blockquote> Why would I need this tool? <blockquote>While editing files on a machine running some form of Windows and uploading them to a Linux server is convenient, it can cause unforeseen complications. Windows-based text editors put special characters at the end of lines to denote a line return or newline. Normally harmless, some applications on a Linux server cannot understand these characters and can cause the service to not respond correctly. There is a simple way to correct this problem: dos2unix.</blockquote> The dos2unix command is a simple way to make sure that files that have been edited and uploaded from a Windows machine to a Linux machine work and behave correctly. ===Disk Space===
<pre>#!/bin/bash
 
Black<nowiki>=</nowiki>'\e[0;30m'
Blue<nowiki>=</nowiki>'\e[0;34m'
Yellow<nowiki>=</nowiki>'\e[1;33m'
White<nowiki>=</nowiki>'\e[1;37m'
 
Blink<nowiki>=</nowiki>'\033[5m'
Bold<nowiki>=</nowiki>'\033[1m'
Underline<nowiki>=</nowiki>'\033[4m'
 
No_Color<nowiki>=</nowiki>'\033[0m'
 
TermSize<nowiki>=</nowiki>`tput cols`
 
if [ $TermSize -gt "81" ]; then
TermSize<nowiki>=</nowiki>81
fi
 
function Print {
# Disk I don't care about.
if [ $DISK <nowiki>=</nowiki> "none" ] <nowiki>|</nowiki><nowiki>|</nowiki> [ $DISK <nowiki>=</nowiki> "/dev/sda3" ] <nowiki>|</nowiki><nowiki>|</nowiki> [ $DISK <nowiki>=</nowiki> "/dev/pts" ] <nowiki>|</nowiki><nowiki>|</nowiki> [ $DISK <nowiki>=</nowiki> "/dev/shm" ] <nowiki>|</nowiki><nowiki>|</nowiki> [[ $DISK <nowiki>=</nowiki>~ /dev/sr.* ]]; then
continue
fi
 
read SIZE USED FREE PERCENT <<< $(df -hP 2> /dev/null<nowiki>|</nowiki>grep $DISK<nowiki>|</nowiki>awk '{print $2" "$3" "$4" "$5}')
PERCENT<nowiki>=</nowiki>$(echo $PERCENT<nowiki>|</nowiki>sed s/%//)
BarSize<nowiki>=</nowiki>$(echo "($PERCENT*($TermSize-3))/100"<nowiki>|</nowiki>bc)
 
 
if [ "$PERCENT" -gt "90" ]; then
Color<nowiki>=</nowiki>$Light_Red
Color<nowiki>=</nowiki>$Light_Green
fi
 
echo "Partition: $DISK"
#echo
echo -ne "Used space percent: $PERCENT%"
echo
 
echo -ne "["
for i in `seq 1 $BarSize`; do
echo -ne "${Color}#"
echo -ne "${No_Color}"
done
 
for i in `seq 1 $(echo "$TermSize-$BarSize-3"<nowiki>|</nowiki>bc)`; do
echo -ne "<nowiki>=</nowiki>"
done
 
echo "]"
 
echo -ne "${No_Color}"
echo
}
 
echo
 
if [ "$1" !<nowiki>=</nowiki> "" ]; then
DISK<nowiki>=</nowiki>$1
fi</pre>
===System Info===
<pre>#!/bin/sh
# Variables (server default)
echo</pre>
===Weather===
<pre>#!/bin/sh
 
METRIC<nowiki>=</nowiki>0 # 0 for F, 1 for C
# Find your own code at the end of the url here http://www.accuweather.com/rss-center.asp
# If code has a space; replace with %20
LOCCOD<nowiki>=</nowiki>"95113" #Example: ASI<nowiki>|</nowiki>RU<nowiki>|</nowiki>RS055<nowiki>|</nowiki>NIZHNY%20NOVGOROD
 
if [ -z $1 ] && [ -x $LOCCOD ] ; then
echo
LOCCOD<nowiki>=</nowiki>$1
fi
 
curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\<nowiki>=</nowiki>${METRIC}\&locCode\<nowiki>=</nowiki>$LOCCOD \
<nowiki>|</nowiki> sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'</pre>
=== HDA Updates ===
Here is a simple script that displays all of the file updates and additions made to your hda and the date they happened. It simply reads the hda-updates.log file and parses out only the relevant changes.
# 11/8/2010
#
 log = '/var/log/hda-updates.log' f = open(log, 'r')
lines = f.readlines()
f.close()
 
gotUpdates = False
firstUpdate = False
# 11/8/2010
#
# Updated by bigfoot65# 9/26/2014#
log = '/var/log/hda-updates.log'
 
line = '==============================================================================='
head = 'Package Arch Version Repository Size'
purple = '\033[1;35m'
white = '\033[1;37m'
 
print blue + line + white
print cyan + head + white
print blue + line + white
 
f = open(log, 'r')
lines = f.readlines()
f.close()
 
gotUpdates = False
firstUpdate = False
# A blank line terminates the updates for a particular date
if gotUpdates :
# Display a blank line between dates
print
gotUpdates = False
continue
# Reformat the file info slightly
updateInfo = l.split()
# print ' %-16s %-6s %-20s %-16s %-5s %s' % (tuple(updateInfo))
print purple + l + white
print blue + line + white
Here is a snippet of its output on my system:
Sat Sep 4 15:02:32 PDT 2010:<pre>===============================================================================Package Arch Version Repository hdactl i386 3.Size===============================================================================Fri Sep 5.1-1 amahi 218 k Sat Oct 30 2221:0201:14 PDT 201037 CDT 2014: hdaamahi-greyhole i386 0.6anywhere x86_64 1.2835-1 amahi 47 k hda-platform noarch 5.6-1 amahi 1.0 8 M hdactl i386 3.6-1 amahi 218 k=============================================================================== Sun Nov 7 20Mon Sep 15 23:0103:29 PST 201004 CDT 2014: hda-platform noarch ctl x86_64 5.64.0-8 1 amahi 1.0 M154 k===============================================================================</pre>
= YUM == Fedora Updates ===
<pre>#!/usr/bin/bash
head=' PACKAGE NAME\t\t\t\t\tDATE'
12,424

edits