mirror of
https://github.com/autistic-symposium/shell-whiz-toolkit.git
synced 2025-05-13 12:12:25 -04:00
move shell scripts and zsh and add fav vscode themes
This commit is contained in:
parent
40077637ce
commit
e6794a8954
43 changed files with 55 additions and 34 deletions
12
shell/shell_scripts/SAB.sh
Normal file
12
shell/shell_scripts/SAB.sh
Normal file
|
@ -0,0 +1,12 @@
|
|||
#! /bin/bash
|
||||
#
|
||||
|
||||
echo "Stunnel on?"
|
||||
ps aux | grep stunnel
|
||||
echo
|
||||
echo "Starting secure SABnzbd... "
|
||||
echo
|
||||
python /opt/SABnzbd-0.7.17/SABnzbd.py && google-chrome localhost:8080/sabnzbd
|
||||
echo
|
||||
echo "Remember to kill the process after closing the browser!!!"
|
||||
echo
|
6
shell/shell_scripts/USENET.sh
Normal file
6
shell/shell_scripts/USENET.sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
stunnel
|
||||
clear
|
||||
echo
|
||||
echo "Type sab and sickbeard ..."
|
||||
echo
|
19
shell/shell_scripts/backup.sh
Normal file
19
shell/shell_scripts/backup.sh
Normal file
|
@ -0,0 +1,19 @@
|
|||
i#!/bin/bash
|
||||
|
||||
# saving things at /home
|
||||
echo "Starting backup..."
|
||||
|
||||
cd YOUR_BACKUP_FOLDER
|
||||
mkdir `date +%m-%d-%Y-$HOSTNAME`
|
||||
cd `date +%m-%d-%Y-$HOSTNAME`
|
||||
|
||||
|
||||
cp ~/.bashrc bashrc
|
||||
cp /etc/issue.net .
|
||||
cp ~/.config/sublime-text-3/Packages/User/Preferences.sublime-settings .
|
||||
|
||||
# AND OTHER CONF FILES YOU WANT TO SAVE
|
||||
|
||||
echo "Done!"
|
||||
|
||||
|
9
shell/shell_scripts/bye.sh
Executable file
9
shell/shell_scripts/bye.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
echo
|
||||
echo "Before leaving..."
|
||||
echo
|
||||
echo "Did you $ backup?"
|
||||
echo
|
||||
echo "Did you $ git everything?"
|
||||
echo
|
||||
echo "<3 Bye, $LOGNAME! <3"
|
||||
echo
|
16
shell/shell_scripts/check_if_req_are_update.sh
Executable file
16
shell/shell_scripts/check_if_req_are_update.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
# Script for testing if our requirements are up-to-date
|
||||
rm -rf test_requirements/
|
||||
mkdir test_requirements/
|
||||
cd test_requirements/
|
||||
virtualenv venv
|
||||
. venv/bin/activate
|
||||
pip install ../ -i https://pypi.yelpcorp.com/simple
|
||||
pip freeze -l | grep -v '^styleguide==' > requirements.txt
|
||||
diff -u ../requirements.txt requirements.txt
|
||||
cd ../
|
||||
rm -rf test_requirements/
|
||||
|
||||
echo -e '\033[42mSuccess!\033[0m'
|
23
shell/shell_scripts/check_port_network.sh
Normal file
23
shell/shell_scripts/check_port_network.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
# Check a whether a port is open or not
|
||||
#
|
||||
# then use the script in your tests like
|
||||
# check_port 9200
|
||||
|
||||
function check_port() {
|
||||
local host=${1} && shift
|
||||
local port=${1} && shift
|
||||
local retries=5
|
||||
local wait=1
|
||||
|
||||
until( nc -zv "${host}" "${port}" ); do
|
||||
((retries--))
|
||||
if [ $retries -lt 0 ]; then
|
||||
echo "Service ${host}:${port} didn't become ready in time."
|
||||
exit 1
|
||||
fi
|
||||
sleep "${wait}"
|
||||
done
|
||||
}
|
||||
|
||||
check_port "localhost" "$@"
|
9
shell/shell_scripts/check_time_zone.sh
Normal file
9
shell/shell_scripts/check_time_zone.sh
Normal file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Set a random timezone
|
||||
TZ_SIGN=$( echo "+:-" | cut -d: -f "$( shuf -i 1-2 -n 1 )" )
|
||||
TZ=UTC${TZ_SIGN}$( shuf -i 0-24 -n1 )
|
||||
|
||||
export TZ
|
||||
|
||||
echo "Set TZ to: ${TZ}"
|
15
shell/shell_scripts/find_if_file_exists.sh
Executable file
15
shell/shell_scripts/find_if_file_exists.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
if [ $# -ne 1 ]
|
||||
then
|
||||
echo "Usage - $0 file-name"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f $1 ]
|
||||
then
|
||||
echo "$1 file exist"
|
||||
else
|
||||
echo "Sorry, $1 file does not exist"
|
||||
fi
|
11
shell/shell_scripts/i2p.sh
Normal file
11
shell/shell_scripts/i2p.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
echo "--------------------------------------------------"
|
||||
echo
|
||||
echo "Starting i2p..."
|
||||
echo
|
||||
echo " Don't forget to proxy the browser or the network"
|
||||
echo " with 127.0.0.1, ports 4444 and 4445"
|
||||
echo
|
||||
echo "--------------------------------------------------"
|
||||
echo
|
||||
cd ~/i2p/
|
||||
./i2prouter start
|
97
shell/shell_scripts/lessons/TRICKS.md
Normal file
97
shell/shell_scripts/lessons/TRICKS.md
Normal file
|
@ -0,0 +1,97 @@
|
|||
Wild Cards
|
||||
----------
|
||||
|
||||
Use *, ? (for one char), and [abc] for a series of options. Example:
|
||||
|
||||
$ ls [abc]*
|
||||
|
||||
|
||||
More commands on one line
|
||||
-------------------------
|
||||
|
||||
Use ;
|
||||
$ date;who
|
||||
|
||||
|
||||
Redirection of Standard output/input
|
||||
-----------------------------------
|
||||
|
||||
>, >>, <
|
||||
|
||||
Examples:
|
||||
|
||||
$ sort < filename > sorted_names
|
||||
|
||||
|
||||
Pipes
|
||||
-----
|
||||
A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for second command.
|
||||
|
||||
|
||||
Processes and PID
|
||||
-----------------
|
||||
An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process.
|
||||
|
||||
ps - show current running
|
||||
kill {PID} - kill process
|
||||
kill 0 - stop all processes except shell
|
||||
& - background process
|
||||
ps aux - display the owner of the processes along with the processes
|
||||
ps -ag - get information of all running processes
|
||||
ps ax | grep processes-you-want-to-see
|
||||
top - see currently running processes and other information like memory and CPU
|
||||
pstree - display a tree of processes
|
||||
|
||||
|
||||
|
||||
Useful Cmds:
|
||||
------------
|
||||
|
||||
List size of folders
|
||||
$ du -sh *
|
||||
|
||||
Print calendar:
|
||||
$ cal
|
||||
|
||||
Writing and creating a file:
|
||||
$ cat > NEWFILE
|
||||
|
||||
--- write here ---
|
||||
^D
|
||||
|
||||
|
||||
De-bug Shell Script
|
||||
-------------------
|
||||
|
||||
Use -v and -x option:
|
||||
$ sh option SCRIPT
|
||||
$ bash option SCRIPT
|
||||
|
||||
|
||||
Local and Global Variables
|
||||
-------------------------
|
||||
|
||||
Whenever you type:
|
||||
$ /bin/bash
|
||||
You start a new shell where the previous variables will be forgotten (local variables). To make variables global, you can do:
|
||||
$ export VARIABLE-NAME
|
||||
Before changing shell.
|
||||
|
||||
|
||||
Conditional Execution
|
||||
---------------------
|
||||
|
||||
The control operators are && (AND) and || (OR).
|
||||
$ rm myf && echo "File is removed successfully" || echo "File is not removed"
|
||||
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
$ SayHello()
|
||||
{
|
||||
echo "Hello $LOGNAME, Have nice computing"
|
||||
return
|
||||
}
|
||||
To execute this SayHello() function just type it name as follows:
|
||||
$ SayHello
|
15
shell/shell_scripts/lessons/arguments.ssh
Executable file
15
shell/shell_scripts/lessons/arguments.ssh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#! /bin/bash
|
||||
# script to test for loop and arguments
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
echo "Error - Number missing form command line argument"
|
||||
echo "Syntax : $0 number"
|
||||
echo "Use to print multiplication table for given number"
|
||||
exit 1
|
||||
fi
|
||||
n=$1
|
||||
for i in 1 2 3 4 5 6 7 8 9 10
|
||||
do
|
||||
echo "$n * $i = `expr $i \* $n`"
|
||||
done
|
31
shell/shell_scripts/lessons/average_number.sh
Executable file
31
shell/shell_scripts/lessons/average_number.sh
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
|
||||
avg=0
|
||||
temp_total=0
|
||||
number_of_args=$#
|
||||
|
||||
#
|
||||
# First see the sufficient cmd args
|
||||
#
|
||||
if [ $# -lt 2 ] ; then
|
||||
echo -e "Opps! I need atleast 2 command line args\n"
|
||||
echo -e "Syntax: $0: number1 number2 ... numberN\n"
|
||||
echo -e "Example:$0 5 4\n\t$0 56 66 34"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# now calculate the average of numbers given on command line as cmd args
|
||||
#
|
||||
|
||||
for i in $*
|
||||
do
|
||||
|
||||
# addition of all the numbers on cmd args
|
||||
temp_total=`expr $temp_total + $i`
|
||||
|
||||
done
|
||||
|
||||
avg=`expr $temp_total / $number_of_args`
|
||||
echo "Average of all number is $avg"
|
18
shell/shell_scripts/lessons/case_loop_example.sh
Executable file
18
shell/shell_scripts/lessons/case_loop_example.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
# script to test case statement
|
||||
|
||||
if [ -z $1 ]
|
||||
then
|
||||
r="*** unknown ***"
|
||||
elif [ -n $1 ]
|
||||
then
|
||||
r=$1
|
||||
fi
|
||||
|
||||
case $r in
|
||||
"car") echo "car rental";;
|
||||
"van") echo "van rental";;
|
||||
"jeep") echo "jeep rental";;
|
||||
*) echo "Sorry I have no $r !";;
|
||||
esac
|
18
shell/shell_scripts/lessons/cheesboard.sh
Executable file
18
shell/shell_scripts/lessons/cheesboard.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#! /bin/bash
|
||||
# script to print a chessboard
|
||||
|
||||
for (( i = 1; i <= 9; i++ ))
|
||||
do
|
||||
for (( j = 1; j <= 9; j++))
|
||||
do
|
||||
tot=`expr $i + $j` # notice that these tot must have no space to =
|
||||
tmp=`expr $tot % 2`
|
||||
if [ $tmp -eq 0 ]; then
|
||||
echo -e -n "\033[47m "
|
||||
else
|
||||
echo -e -n "\033[40m "
|
||||
fi
|
||||
done
|
||||
echo -e -n "\033[40m" # set to black
|
||||
echo"" # print new line
|
||||
done
|
9
shell/shell_scripts/lessons/echo_cmds.sh
Executable file
9
shell/shell_scripts/lessons/echo_cmds.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#! /bin/bash
|
||||
echo "The echo commands are (use echo -e):"
|
||||
echo
|
||||
echo -e "\a alert "
|
||||
echo -e "\n new line"
|
||||
echo -e "\t horizontal tab"
|
||||
echo -e "\c suppress trailing line"
|
||||
echo -e "\r carriage return"
|
||||
echo -e "\b backspace"
|
18
shell/shell_scripts/lessons/factorial.sh
Executable file
18
shell/shell_scripts/lessons/factorial.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#! /bin/bash
|
||||
|
||||
n=0
|
||||
on=0
|
||||
fact=1
|
||||
|
||||
echo -n "Enter number to find factorial : "
|
||||
read n
|
||||
|
||||
on=$n
|
||||
|
||||
while [ $n -ge 1 ]
|
||||
do
|
||||
fact=`expr $fact \* $n`
|
||||
n=`expr $n - 1`
|
||||
done
|
||||
|
||||
echo "Factorial for $on is $fact"
|
12
shell/shell_scripts/lessons/file_descriptors.sh
Executable file
12
shell/shell_scripts/lessons/file_descriptors.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/sh
|
||||
|
||||
# from > & destination
|
||||
|
||||
if [ $# -ne 2 ]
|
||||
then
|
||||
echo "Error!" 1>&2
|
||||
echo "Usae: $0 number1 number2"
|
||||
exit 1
|
||||
fi
|
||||
ans=`expr $1 + $2`
|
||||
echo "Sum = $ans"
|
11
shell/shell_scripts/lessons/for_loop_example.sh
Executable file
11
shell/shell_scripts/lessons/for_loop_example.sh
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
for p in 1 2 3 4 5
|
||||
do
|
||||
echo $p
|
||||
done
|
||||
|
||||
for p in `seq 6 10`
|
||||
do
|
||||
echo $p
|
||||
done
|
59
shell/shell_scripts/lessons/getopts.sh
Executable file
59
shell/shell_scripts/lessons/getopts.sh
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
|
||||
# Usage: ./geotopts.sh -n -a -s -w -d
|
||||
#
|
||||
#
|
||||
# help_ani() To print help
|
||||
#
|
||||
help_ani()
|
||||
{
|
||||
echo "Usage: $0 -n -a -s -w -d"
|
||||
echo "Options: These are optional argument"
|
||||
echo " -n name of animal"
|
||||
echo " -a age of animal"
|
||||
echo " -s sex of animal "
|
||||
echo " -w weight of animal"
|
||||
echo " -d demo values (if any of the above options are used "
|
||||
echo " their values are not taken)"
|
||||
exit 1
|
||||
}
|
||||
#
|
||||
#Start main procedure
|
||||
#
|
||||
#
|
||||
#Set default value for variable
|
||||
#
|
||||
isdef=0
|
||||
na=Moti
|
||||
age="2 Months" # may be 60 days, as U like it!
|
||||
sex=Male
|
||||
weight=3Kg
|
||||
#
|
||||
#if no argument
|
||||
#
|
||||
if [ $# -lt 1 ]; then
|
||||
help_ani
|
||||
fi
|
||||
while getopts n:a:s:w:d opt
|
||||
do
|
||||
case "$opt" in
|
||||
n) na="$OPTARG";;
|
||||
a) age="$OPTARG";;
|
||||
s) sex="$OPTARG";;
|
||||
w) weight="$OPTARG";;
|
||||
d) isdef=1;;
|
||||
\?) help_ani;;
|
||||
esac
|
||||
done
|
||||
if [ $isdef -eq 0 ]
|
||||
then
|
||||
echo "Animal Name: $na, Age: $age, Sex: $sex, Weight: $weight (user define mode)"
|
||||
else
|
||||
na="Pluto Dog"
|
||||
age=3
|
||||
sex=Male
|
||||
weight=20kg
|
||||
echo "Animal Name: $na, Age: $age, Sex: $sex, Weight: $weight (demo mode)"
|
||||
fi
|
10
shell/shell_scripts/lessons/hex_converter_real_numbers.sh
Executable file
10
shell/shell_scripts/lessons/hex_converter_real_numbers.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#! /bin/bash
|
||||
|
||||
n=0
|
||||
hex=0
|
||||
echo "Decimal to hexadecimal converter:"
|
||||
echo -n "Enter number in decimal format : "
|
||||
read n
|
||||
hex=`echo "obase=16;ibase=10; $n" | bc`
|
||||
echo "$n is equivalent \"$hex\" in hexadecimal"
|
||||
|
70
shell/shell_scripts/lessons/if_example.sh
Executable file
70
shell/shell_scripts/lessons/if_example.sh
Executable file
|
@ -0,0 +1,70 @@
|
|||
#! /bin/bash
|
||||
#
|
||||
#Syntax:
|
||||
# if condition
|
||||
# then
|
||||
# if condition
|
||||
# then
|
||||
# .....
|
||||
# ..
|
||||
# do this
|
||||
# else
|
||||
# ....
|
||||
# ..
|
||||
# do this
|
||||
# fi
|
||||
# else
|
||||
# ...
|
||||
# .....
|
||||
# do this
|
||||
# fi
|
||||
#
|
||||
# You can also use
|
||||
# elif
|
||||
# ...
|
||||
# then
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
echo "Here an example of how to use if condition for numbers:"
|
||||
echo
|
||||
echo "Type a number from 1 to 10:"
|
||||
read number
|
||||
if test $number -gt 5
|
||||
then
|
||||
echo "This number is larger than 5"
|
||||
fi
|
||||
if test $number -lt 5
|
||||
then
|
||||
echo "This number is smaller than 5"
|
||||
fi
|
||||
echo
|
||||
echo "Operators are: -eq, -ne, -lt, -gt, -ge"
|
||||
echo
|
||||
echo "****************************************************"
|
||||
echo
|
||||
echo "Here an example of how to use if condition for strings:"
|
||||
echo
|
||||
echo "Type a number your name:"
|
||||
read name
|
||||
if test $name != "john"
|
||||
then
|
||||
echo "Your name is not John, its $name"
|
||||
else
|
||||
echo "Your name is john! What the odds?"
|
||||
fi
|
||||
echo
|
||||
echo "Operators are: =, !=, -n (not null, exist), -z null (exist)"
|
||||
echo
|
||||
echo "****************************************************"
|
||||
echo
|
||||
echo "Here an example of how to use if condition for files:"
|
||||
echo
|
||||
echo "Operators are: -s (non empty), -f (exist), -d (directory exist), -w (writeable), -r (read-only), -x (executable)"
|
||||
echo
|
||||
echo "****************************************************"
|
||||
echo
|
||||
echo "Here an example of how to use logical operators:"
|
||||
echo
|
||||
echo "Operators are: ! (NOT), -a (AND), -o (OR)"
|
7
shell/shell_scripts/lessons/inputs.sh
Executable file
7
shell/shell_scripts/lessons/inputs.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#! /bin/bash
|
||||
echo "We use read to read an input"
|
||||
echo
|
||||
echo "Type your name: "
|
||||
read fname
|
||||
echo "You name is $fname"
|
||||
echo
|
15
shell/shell_scripts/lessons/linux_console.sh
Executable file
15
shell/shell_scripts/lessons/linux_console.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#! /bin/bash
|
||||
echo "The Linux Console variables are:"
|
||||
echo
|
||||
echo "\33 is the escape char, to take an action. Ex: using \033[34m:"
|
||||
echo -e "\033[34m Hello! \033[0m"
|
||||
echo
|
||||
echo " [ is the start, 34 the parameter, m is the letter (action)"
|
||||
echo " letters can be h, l, m, q, s, u..."
|
||||
echo " parameters can be 0, 1 (bold), 2 (dim intensity), 5 (blink), 7 (reverse), 11, 25, 27, 30-27 (colors), 4047 (bkgd colors)..."
|
||||
echo
|
||||
echo "For example:"
|
||||
echo -e "\033[5m Hey! \033[0m"
|
||||
echo
|
||||
echo "Now, quotes... the black quote is used to execute a cmd (\`cmd\`)"
|
||||
echo
|
49
shell/shell_scripts/lessons/menu_fancy.sh
Executable file
49
shell/shell_scripts/lessons/menu_fancy.sh
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# dialog --title {title} --backtitle {backtitle} {Box options}
|
||||
# where Box options can be any one of following
|
||||
# --yesno {text} {height} {width}
|
||||
# --msgbox {text} {height} {width}
|
||||
# --infobox {text} {height} {width}
|
||||
# --inputbox {text} {height} {width} [{init}]
|
||||
# --textbox {file} {height} {width}
|
||||
# --menu {text} {height} {width} {menu} {height} {tag1} item1}...
|
||||
#
|
||||
#
|
||||
|
||||
dialog \
|
||||
--title "Hello $LOGNAME" \
|
||||
--backtitle "Linux Shell Script - Bytegirl Tutorial" \
|
||||
--msgbox "This is dialog box called infobox, which is used \
|
||||
to show some information on screen, Thanks to Savio Lam and\
|
||||
Stuart Herbert to give us this utility. Press any key. . . " \
|
||||
9 50 ; read
|
||||
|
||||
|
||||
|
||||
dialog --title "Alert : Delete File" --backtitle "Linux Shell Script\
|
||||
Tutorial" --yesno "\nDo you want to delete '/usr/letters/jobapplication'\
|
||||
file" 7 60
|
||||
sel=$?
|
||||
case $sel in
|
||||
0) echo "User select to delete file";;
|
||||
1) echo "User select not to delete file";;
|
||||
255) echo "Canceled by user by pressing [ESC] key";;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
$ cat > dia4
|
||||
dialog --title "Inputbox - To take input from you" --backtitle "Linux Shell\
|
||||
Script Tutorial" --inputbox "Enter your name please" 8 60 2>/tmp/input.$$
|
||||
|
||||
sel=$?
|
||||
|
||||
na=`cat /tmp/input.$$`
|
||||
case $sel in
|
||||
0) echo "Hello $na" ;;
|
||||
1) echo "Cancel is Press" ;;
|
||||
255) echo "[ESCAPE] key pressed" ;;
|
||||
esac
|
||||
|
||||
rm -f /tmp/input.$$
|
26
shell/shell_scripts/lessons/real_numbers.sh
Executable file
26
shell/shell_scripts/lessons/real_numbers.sh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#! /bin/bash
|
||||
|
||||
|
||||
a=0
|
||||
b=0
|
||||
number_of_args=$#
|
||||
|
||||
#
|
||||
# First see the sufficient cmd args
|
||||
#
|
||||
if [ $# -lt 2 ] ; then
|
||||
echo -e "Opps! I need atleast 2 command line args\n"
|
||||
echo -e "Syntax: $0: number1 number2 ... numberN\n"
|
||||
echo -e "Example:$0 5 4\n\t$0 56 66 34"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# now calculate the average of numbers given on command line as cmd args
|
||||
#
|
||||
|
||||
a=$1
|
||||
b=$2
|
||||
|
||||
c=`echo $a + $b | bc`
|
||||
echo "$a + $b = $c"
|
33
shell/shell_scripts/lessons/red_hello_world.sh
Executable file
33
shell/shell_scripts/lessons/red_hello_world.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
clear
|
||||
echo -e "\033[1m Hello World"
|
||||
# bold effect
|
||||
echo -e "\033[5m Blink"
|
||||
# blink effect
|
||||
echo -e "\033[0m Hello World"
|
||||
# back to noraml
|
||||
|
||||
echo -e "\033[31m Hello World"
|
||||
# Red color
|
||||
echo -e "\033[32m Hello World"
|
||||
# Green color
|
||||
echo -e "\033[33m Hello World"
|
||||
# See remaing on screen
|
||||
echo -e "\033[34m Hello World"
|
||||
echo -e "\033[35m Hello World"
|
||||
echo -e "\033[36m Hello World"
|
||||
|
||||
echo -e -n "\033[0m "
|
||||
# back to noraml
|
||||
|
||||
echo -e "\033[41m Hello World"
|
||||
echo -e "\033[42m Hello World"
|
||||
echo -e "\033[43m Hello World"
|
||||
echo -e "\033[44m Hello World"
|
||||
echo -e "\033[45m Hello World"
|
||||
echo -e "\033[46m Hello World"
|
||||
|
||||
|
||||
echo -e "\033[0m Hello World"
|
12
shell/shell_scripts/lessons/shell_variables.sh
Executable file
12
shell/shell_scripts/lessons/shell_variables.sh
Executable file
|
@ -0,0 +1,12 @@
|
|||
#! /bin/bash
|
||||
echo "The variable of the system are:"
|
||||
echo
|
||||
echo "BASH_VERSION: " $BASH_VERSION
|
||||
echo "LOGNAME: " $LOGNAME
|
||||
echo "OSTYPE: " $OSTYPE
|
||||
echo "PATH: " $PATH
|
||||
echo "PWD: " $PWD
|
||||
echo "USERNAME: " $USERNAME
|
||||
echo
|
||||
echo "Linux distribution, name, arch: $ uname -a"
|
||||
echo
|
16
shell/shell_scripts/lessons/while_loop_example.sh
Executable file
16
shell/shell_scripts/lessons/while_loop_example.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
# script to test while statement
|
||||
|
||||
if [ $# -eq 0 ] # note the spaces
|
||||
then
|
||||
echo "Error, missing argument!"
|
||||
exit 1
|
||||
fi
|
||||
n=$1
|
||||
i=1
|
||||
while [ $i -le 10 ]
|
||||
do
|
||||
echo "$n * $i = `expr $i \* $n`"
|
||||
i=`expr $i + 1`
|
||||
done
|
30
shell/shell_scripts/menu.sh
Executable file
30
shell/shell_scripts/menu.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
|
||||
# Script to create simple menus and take action according to that selected
|
||||
# menu item
|
||||
#
|
||||
while :
|
||||
do
|
||||
clear
|
||||
echo "-------------------------------------"
|
||||
echo " Main Menu "
|
||||
echo "-------------------------------------"
|
||||
echo "[1] Show Todays date/time"
|
||||
echo "[2] Show files in current directory"
|
||||
echo "[3] Show calendar"
|
||||
echo "[4] Start editor to write letters"
|
||||
echo "[5] Exit/Stop"
|
||||
echo "======================="
|
||||
echo -n "Enter your menu choice [1-5]: "
|
||||
read yourch
|
||||
case $yourch in
|
||||
1) echo "Today is `date` , press a key. . ." ; read ;;
|
||||
2) echo "Files in `pwd`" ; ls -l ; echo "Press a key. . ." ; read ;;
|
||||
3) cal ; echo "Press a key. . ." ; read ;;
|
||||
4) vi ;;
|
||||
5) exit 0 ;;
|
||||
*) echo "Opps!!! Please select choice 1,2,3,4, or 5";
|
||||
echo "Press a key. . ." ; read ;;
|
||||
esac
|
||||
done
|
88
shell/shell_scripts/post_install_ubuntu.sh
Normal file
88
shell/shell_scripts/post_install_ubuntu.sh
Normal file
|
@ -0,0 +1,88 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
# Post-installation bash script for Ubuntu
|
||||
|
||||
|
||||
tabs 4
|
||||
|
||||
|
||||
TITLE="Ubuntu Post-Install Script"
|
||||
|
||||
|
||||
function main {
|
||||
echo_message header "Starting 'main' function"
|
||||
# Draw window
|
||||
MAIN=$(eval `resize` && whiptail \
|
||||
--notags \
|
||||
--title "$TITLE" \
|
||||
--menu "\nWhat would you like to do?" \
|
||||
--cancel-button "Quit" \
|
||||
$LINES $COLUMNS $(( $LINES - 12 )) \
|
||||
'system_update' 'Perform system updates' \
|
||||
'install_favs' 'Install preferred applications' \
|
||||
'install_favs_dev' 'Install preferred development tools' \
|
||||
'install_favs_utils' 'Install preferred utilities' \
|
||||
'install_gnome' 'Install preferred GNOME software' \
|
||||
'install_codecs' 'Install multimedia codecs' \
|
||||
'install_fonts' 'Install additional fonts' \
|
||||
'install_snap_apps' 'Install Snap applications' \
|
||||
'install_flatpak_apps' 'Install Flatpak applications' \
|
||||
'install_thirdparty' 'Install third-party applications' \
|
||||
'setup_dotfiles' 'Configure dotfiles' \
|
||||
'system_configure' 'Configure system' \
|
||||
'system_cleanup' 'Cleanup the system' \
|
||||
3>&1 1>&2 2>&3)
|
||||
# check exit status
|
||||
if [ $? = 0 ]; then
|
||||
echo_message header "Starting '$MAIN' function"
|
||||
$MAIN
|
||||
else
|
||||
# Quit
|
||||
quit
|
||||
fi
|
||||
}
|
||||
|
||||
# Quit
|
||||
function quit {
|
||||
echo_message header "Starting 'quit' function"
|
||||
echo_message title "Exiting $TITLE..."
|
||||
# Draw window
|
||||
if (whiptail --title "Quit" --yesno "Are you sure you want quit?" 8 56) then
|
||||
echo_message welcome 'Thanks for using!'
|
||||
exit 99
|
||||
else
|
||||
main
|
||||
fi
|
||||
}
|
||||
|
||||
# Import Functions
|
||||
function import_functions {
|
||||
DIR="functions"
|
||||
# iterate through the files in the 'functions' folder
|
||||
for FUNCTION in $(dirname "$0")/$DIR/*; do
|
||||
# skip directories
|
||||
if [[ -d $FUNCTION ]]; then
|
||||
continue
|
||||
# exclude markdown readmes
|
||||
elif [[ $FUNCTION == *.md ]]; then
|
||||
continue
|
||||
elif [[ -f $FUNCTION ]]; then
|
||||
# source the function file
|
||||
. $FUNCTION
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Import main functions
|
||||
import_functions
|
||||
# Welcome message
|
||||
echo_message welcome "$TITLE"
|
||||
# Run system checks
|
||||
system_checks
|
||||
# main
|
||||
while :
|
||||
do
|
||||
main
|
||||
done
|
||||
|
33
shell/shell_scripts/red_hello_world.sh
Executable file
33
shell/shell_scripts/red_hello_world.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
|
||||
clear
|
||||
echo -e "\033[1m Hello World"
|
||||
# bold effect
|
||||
echo -e "\033[5m Blink"
|
||||
# blink effect
|
||||
echo -e "\033[0m Hello World"
|
||||
# back to noraml
|
||||
|
||||
echo -e "\033[31m Hello World"
|
||||
# Red color
|
||||
echo -e "\033[32m Hello World"
|
||||
# Green color
|
||||
echo -e "\033[33m Hello World"
|
||||
# See remaing on screen
|
||||
echo -e "\033[34m Hello World"
|
||||
echo -e "\033[35m Hello World"
|
||||
echo -e "\033[36m Hello World"
|
||||
|
||||
echo -e -n "\033[0m "
|
||||
# back to noraml
|
||||
|
||||
echo -e "\033[41m Hello World"
|
||||
echo -e "\033[42m Hello World"
|
||||
echo -e "\033[43m Hello World"
|
||||
echo -e "\033[44m Hello World"
|
||||
echo -e "\033[45m Hello World"
|
||||
echo -e "\033[46m Hello World"
|
||||
|
||||
|
||||
echo -e "\033[0m Hello World"
|
3
shell/shell_scripts/rsync.sh
Executable file
3
shell/shell_scripts/rsync.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
VM=vm_dev
|
||||
rsync -avz -e ssh <local dir> ${VM}:<remote dir> --exclude-from ~/.rsync-excludes
|
7
shell/shell_scripts/secure_pan.sh
Normal file
7
shell/shell_scripts/secure_pan.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Starting a secure pan connection..."
|
||||
|
||||
sudo stunnel
|
||||
ps aux | grep stunnel
|
||||
pan
|
3
shell/shell_scripts/sshfs.sh
Executable file
3
shell/shell_scripts/sshfs.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
/usr/local/bin/sshfs vm_dev:<remove dir> <mount local dir>
|
61
shell/shell_scripts/system_info.sh
Executable file
61
shell/shell_scripts/system_info.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
|
||||
nouser=`who | wc -l`
|
||||
echo -e "User name: $USER (Login name: $LOGNAME)" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Current Shell: $SHELL" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Home Directory: $HOME" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Your O/s Type: $OSTYPE" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "PATH: $PATH" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Current directory: `pwd`" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Currently Logged: $nouser user(s)" >> /tmp/info.tmp.01.$$$
|
||||
|
||||
if [ -f /etc/redhat-release ]
|
||||
then
|
||||
echo -e "OS: `cat /etc/redhat-release`" >> /tmp/info.tmp.01.$$$
|
||||
fi
|
||||
|
||||
if [ -f /etc/shells ]
|
||||
then
|
||||
echo -e "Available Shells: " >> /tmp/info.tmp.01.$$$
|
||||
echo -e "`cat /etc/shells`" >> /tmp/info.tmp.01.$$$
|
||||
fi
|
||||
|
||||
if [ -f /etc/sysconfig/mouse ]
|
||||
then
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Computer Mouse Information: " >> /tmp/info.tmp.01.$$$
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "`cat /etc/sysconfig/mouse`" >> /tmp/info.tmp.01.$$$
|
||||
fi
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Computer CPU Information:" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
cat /proc/cpuinfo >> /tmp/info.tmp.01.$$$
|
||||
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Computer Memory Information:" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
cat /proc/meminfo >> /tmp/info.tmp.01.$$$
|
||||
|
||||
if [ -d /proc/ide/hda ]
|
||||
then
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Hard disk information:" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Model: `cat /proc/ide/hda/model` " >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Driver: `cat /proc/ide/hda/driver` " >> /tmp/info.tmp.01.$$$
|
||||
echo -e "Cache size: `cat /proc/ide/hda/cache` " >> /tmp/info.tmp.01.$$$
|
||||
fi
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "File System (Mount):" >> /tmp/info.tmp.01.$$$
|
||||
echo -e "--------------------------------------------------------------------" >> /tmp/info.tmp.01.$$$
|
||||
cat /proc/mounts >> /tmp/info.tmp.01.$$$
|
||||
|
||||
if which dialog > /dev/null
|
||||
then
|
||||
dialog --backtitle "Linux Software Diagnostics (LSD) Shell Script Ver.1.0" --title "Press Up/Down Keys to move" --textbox /tmp/info.tmp.01.$$$ 21 70
|
||||
else
|
||||
cat /tmp/info.tmp.01.$$$ |more
|
||||
fi
|
||||
|
||||
rm -f /tmp/info.tmp.01.$$$
|
Loading…
Add table
Add a link
Reference in a new issue