Anything you can normally run on the command line can also be put into a script for repeated use.
A user will not have permission to run a saved script by default. We need to grant it first:
chmod a+x script.sh
To run the script:
./script.sh
To schedule scripts with CRON:
crontab -e
Edit the file to run a script every minute:
* * * * * ~/script.sh
#!/bin/bash
sudo apt-get udpate &&
sudo apt-get upgrade -y &&
sudo apt-get dist-upgrade -y
#!/bin/bash
declare -i number1
declare -i number2
declare -i total
echo "Enter a number..."
read number1
echo "Enter next number..."
read number2
total=$number1+$number2
echo "The sum of these numbers equals " $total
exit 0
#!/bin/bash
for i in {0..10..2}
do
echo "We've been through this $i times!"
done
#!/bin/bash
for filename in file1 file2 file3
do
echo "Uhn tiss..." >> $filename
done
#!/bin/bash
echo "What is your favorite color? "
read text1
echo "What is your friend's favorite color? "
read text2
if test $text1 != $text2; then
echo "I guess opposites attract."
else
echo "You two do think alike!"
fi
exit 0
#!/bin/bash
declare -i counter
counter=10
while [ $counter -gt 2 ];do
echo "The counter is $counter"
counter=counter-1
done
exit 0
#!/bin/bash
echo "What's the weather going to be like tomorrow?"
read weather
case $weather in
sunny | warm ) echo "Nice! I love it when it's $weather."
;;
cloudy | cool ) echo "Not bad... $weather is ok."
;;
rainy | cold ) echo "Yuk! $weather weather is depressing."
;;
* ) echo "Sorry, I'm not familiar with that weather system."
;;
esac
exit 0
#!/bin/bash
originalAddress=$( ifconfig |
grep "inet " |
head -n 1 |
tr -s ' ' |
cut -d ' ' -f 3)
echo $originalAddress >> ~/Desktop/ip.txt
#!/bin/bash
while [ : ]
do
originalAddress=$( ifconfig |
grep "inet " |
head -n 1 |
tr -s ' ' |
cut -d ' ' -f 3)
echo "$(date) $originalAddress" >> ~/Desktop/ip.txt
sleep 10
done
To watch the output updating every 10s:
tail ip.txt -f