script for using trim on a ssd and a wake on lan script
Posted: Sat Jul 12, 2014 8:45 pm
I'm working on learning how to make a pretty user interface and searching for something like kdialog. I will give zenity a try and repost when it's done in the future but for now heres something you can run in a terminal.
If you make any changes to make these scripts better which shouldn't be too hard please share them with everyone :)
you will have to make simple changes depending on where you put the script and the sda's that are ssd you might have.
You will notice i use sleep so you can read some fstrim output then clear the screen and return to the menu. Use q or Q to quit. The sleep time is seconds and you can change it to what you prefer.
Heres a very similiar one that can be used for wake on lan and i called it wol.sh
I used wakeonlan because etherwake didn't wake my systems but wakeonlan does.
Test which will work for you and use the one that works.
Where you need to make your changes to match your system should be obvious if not just ask.
If you make any changes to make these scripts better which shouldn't be too hard please share them with everyone :)
you will have to make simple changes depending on where you put the script and the sda's that are ssd you might have.
You will notice i use sleep so you can read some fstrim output then clear the screen and return to the menu. Use q or Q to quit. The sleep time is seconds and you can change it to what you prefer.
Code: Select all
#!/bin/bash
# Script has to be run as root/superuser
# This Script is to be used to trim a ssd drive
# trim command is /sbin/fstrim -v Use of the -v is for verbose
# command for root /sbin/fstrim -v /
# command for home /sbin/fstrim -v /home
# command for additional drive/partition /sbin/fstrim -v /media/Storage
# place script in /usr/local/bin and make executable or
# anywhere in your path where you place your scripts
# you will have to make changes in the script if other than /usr/local/bin
# This is to check if your root/superuser and if not exits and reminds you
if [ $(id -u) != "0" ]; then
/usr/bin/clear
echo
echo -e "You must be root/superuser to run this script\n" >&2
exit 1
fi
# definition of sda1, sda2, sda3, ALL sda's
# sda1 / added as 1
# sda2 /home added as 2
# sda3 /media/Storage added as 3
# All added as a or A
sda1=/
sda2=/home
sda3=/media/Storage
while [ "$input1" != quit ]; do
echo
echo -e "Which SSD would you like to Trim?\n"
# These are menu choice descriptions below
echo -e "1) Trim sda1 /\n"
echo -e "2) Trim sda2 /home\n"
echo -e "3) Trim sda3 /media/Storage\n"
echo -e "a) Trim sda1, sda2, sda3\n"
echo -e "q) quit and take no further action\n"
echo -e "Waiting on your choice\n"
# to trim one at a time
#sda1 /
read input1
if [ $input1 == 1 ]; then
/usr/bin/clear
echo
echo -e "Trim running on sda1\n"
/sbin/fstrim -v $sda1
sleep 3; /usr/bin/clear; /usr/local/bin/trim.sh
exit 1
fi
#sda2 /home
if [ $input1 == 2 ]; then
/usr/bin/clear
echo
echo -e "Trim running on sda2\n"
/sbin/fstrim -v $sda2
sleep 3; /usr/bin/clear; /usr/local/bin/trim.sh
exit 1
fi
#sda3 /media/Storage
if [ $input1 == 3 ]; then
/usr/bin/clear
echo
echo -e "Trim running on sda3\n"
/sbin/fstrim -v $sda3
sleep 3; /usr/bin/clear; /usr/local/bin/trim.sh
exit 1
fi
# to trim all at once
if [ $input1 == A ] || [ $input1 == a ]; then
/usr/bin/clear
echo
echo -e "Trim running on sda1\n"
/sbin/fstrim -v $sda1
echo
echo -e "Trim running on sda2\n"
/sbin/fstrim -v $sda2
echo
echo -e "Trim running on sda3\n"
/sbin/fstrim -v $sda3
sleep 4; /usr/bin/clear; /usr/local/bin/trim.sh
exit 1
fi
if [ $input1 == Q ] || [ $input1 == q ]; then
/usr/bin/clear
echo
echo -e "later gator!\n"
sleep 3; /usr/bin/clear
exit 1
fi
done
Heres a very similiar one that can be used for wake on lan and i called it wol.sh
I used wakeonlan because etherwake didn't wake my systems but wakeonlan does.
Test which will work for you and use the one that works.
Where you need to make your changes to match your system should be obvious if not just ask.
Code: Select all
#!/bin/bash
# get wakeonlan from the repository and install first
# place script in /usr/local/bin and make executable so everyone can use
# definition of MAC addresses for network
# macs for Acer desktop
# Realtek 90:FB:A6:E4:E4:0A
# Wireless 1C:65:9D:15:DA:1C
# menu definitions
# Acer1 desktop realtek added as 1
# Acer2 desktop wireless added as 2
# HTPC added as H or h
# Server added as S or s
# Both added as B or b
# mac definitions
Acer1=90:FB:A6:E4:E4:0A
Acer2=1C:65:9D:15:DA:1C
HTPC=8c:89:a5:37:9d:94
Server=00:40:10:10:00:03
while [ "$input1" != quit ]; do
echo
echo -e "Which PC would you like to wake?\n"
# These are choice descriptions below
echo -e "1) Acer1\n"
echo -e "2) Acer2\n"
echo -e "h) HTPC\n"
echo -e "s) Server\n"
echo -e "b) wake Server, wait 60sec, then wake HTPC\n"
echo -e "q) quit and take no further action\n"
echo -e "Waiting on your choice\n"
read input1
if [ $input1 == 1 ]; then
/usr/bin/clear
echo
/usr/bin/wakeonlan $Acer1
echo
sleep 1; /usr/bin/clear; /usr/local/bin/wol.sh
exit 1
fi
if [ $input1 == 2 ]; then
/usr/bin/clear
echo
/usr/bin/wakeonlan $Acer2
echo
sleep 1; /usr/bin/clear; /usr/local/bin/wol.sh
exit 1
fi
if [ $input1 == H ] || [ $input1 == h ]; then
/usr/bin/clear
echo
/usr/bin/wakeonlan $HTPC
echo
sleep 1; /usr/bin/clear; /usr/local/bin/wol.sh
exit 1
fi
if [ $input1 == S ] || [ $input1 == s ]; then
/usr/bin/clear
echo
/usr/bin/wakeonlan $Server
echo
sleep 1; /usr/bin/clear; /usr/local/bin/wol.sh
exit 1
fi
# to wake Server before the HTPC wakes
if [ $input1 == B ] || [ $input1 == b ]; then
/usr/bin/clear
echo
/usr/bin/wakeonlan $Server
echo
echo -e "Server waking, now waiting for 60sec then waking HTPC\n"
sleep 60
/usr/bin/wakeonlan $HTPC
echo
sleep 2; /usr/bin/clear; /usr/local/bin/wol.sh
exit 1
fi
if [ $input1 == Q ] || [ $input1 == q ]; then
/usr/bin/clear
echo
echo -e "later gator!\n"
sleep 2; /usr/bin/clear
exit 1
fi
done