Script to download the latest linux kernel

Here is a script that will download the latest kernel source kernel.org. THe script works on the current html page of kernel.org and might break if anything is changed in the page of kernel.org.

latest_kernel:

#!/bin/bash latest_kernel () { latest_link=$(grep -A 1 “latest_link” page | tail -1 | cut -d “\”” -f 2 | cut -d “.” -f 2-) prefix=https://www.kernel.org link=$prefix$latest_link for((i=0;i] 17,430 27.8K/s in 0.6s 2013-08-01 22:23:20 (27.8 KB/s) – “page” saved [17430/17430] FINISHED –2013-08-01 22:23:20– Downloaded: 1 files, 17K in 0.6s (27.8 KB/s) downloading from https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.4.tar.xz –2013-08-01 22:23:20– https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.4.tar.xz Resolving www.kernel.org… 149.20.4.69, 198.145.20.140 Connecting to www.kernel.org|149.20.4.69|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 73187712 (70M) [application/x-xz] Saving to: “linux-3.10.4.tar.xz” 100%[===================================================================================>] 73,187,712 97.3K/s in 11m 18s 2013-08-01 22:34:40 (105 KB/s) – “linux-3.10.4.tar.xz” saved [73187712/73187712] Download complete

Thus we can see from the ouput that the latest kernel 3.10.4 has been downloaded. In case the download gets interrupted then the script will retry the download 3 times before quitting with the message of “Download Failed”.

Category: Linux | Comments Off on Script to download the latest linux kernel

Script to download the latest linux kernel

Here is a script that will download the latest kernel source kernel.org. THe script works on the current html page of kernel.org and might break if anything is changed in the page of kernel.org.

latest_kernel:

#!/bin/bash latest_kernel () { latest_link=$(grep -A 1 “latest_link” page | tail -1 | cut -d “\”” -f 2 | cut -d “.” -f 2-) prefix=https://www.kernel.org link=$prefix$latest_link for((i=0;i] 17,430 27.8K/s in 0.6s 2013-08-01 22:23:20 (27.8 KB/s) – “page” saved [17430/17430] FINISHED –2013-08-01 22:23:20– Downloaded: 1 files, 17K in 0.6s (27.8 KB/s) downloading from https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.4.tar.xz –2013-08-01 22:23:20– https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.4.tar.xz Resolving www.kernel.org… 149.20.4.69, 198.145.20.140 Connecting to www.kernel.org|149.20.4.69|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 73187712 (70M) [application/x-xz] Saving to: “linux-3.10.4.tar.xz” 100%[===================================================================================>] 73,187,712 97.3K/s in 11m 18s 2013-08-01 22:34:40 (105 KB/s) – “linux-3.10.4.tar.xz” saved [73187712/73187712] Download complete

Thus we can see from the ouput that the latest kernel 3.10.4 has been downloaded. In case the download gets interrupted then the script will retry the download 3 times before quitting with the message of “Download Failed”.

Category: Linux | Comments Off on Script to download the latest linux kernel

virtual dice on the linux terminal

Here is a script that will act like a dice, a six sided dice, on the terminal.
On running the script, it will display numbers between 1 and 6 randomly, random number of times and at the end settle to one number just as in a usual dice.

dice.sh :

#!/bin/bash roll_dice() { max_dice=$((max_dice-1)) roll=$RANDOM roll=$((roll % max_roll)) roll=$((roll + 1)) n_cols=$(tput cols) col=$((n_cols/2)) for((i=0;i

Category: Linux | Comments Off on virtual dice on the linux terminal

Linux script to create colorful 2013 on the terminal

Here is a script with which you can create the number 2013, on your terminal using any character of your choice. The colors of the numbers will change randomly on every run of hte script.

2013.sh:

#!/bin/bash str_dwn() { rows=$1 s_start=$2 char=$4 str_st_row=$3 rows_end=$((str_st_row+rows)) for((i=str_st_row;i

Category: Linux | Comments Off on Linux script to create colorful 2013 on the terminal

colorful Christmas Tree on linux terminal

Here is a version 2 of the Christmas tree creation script. The script will create a colorful Christmas tree on the terminal. The colors of the tree will change on every run.

The script will take as input the character with which the tree has to be drawn, and any two characters that have to be used to decorated the tree.

Christmas_tree:

#!/bin/bash backslash() { b_st_row=$1 b_st_cols=$2 b_char=$3 deco=$5 b_r_end=$((b_st_row + 5 )) for((p=b_st_row;p

Category: Linux | Comments Off on colorful Christmas Tree on linux terminal

Linux Script to generate random numbers in a given range

Generating random numbers is common recruitment in number of scripts. bash by default gives a variable $RANDOM which when accessed gives a random number between 0 and 32767.

$ echo $RANDOM 4945 $ echo $RANDOM 15819

There might be situations where we might need random numbers between a range of smaller numbers or between zero and a smaller number than 32767. Here is a script which can be used to generate random numbers between any range of numbers.

It takes as input the lower limit and the upper limit of the random numbers required and then generates the required number of random numbers with in the range.

random_numbers

#!/bin/bash echo “Enter range of numbers between which random numbers is required ” echo “lower limit=” read lower echo “upper limit=” read upper echo “How many random numbers do you need” read num diff=$((upper-lower)) echo “Random numbers are ” for((i=0;i

Category: Linux | Comments Off on Linux Script to generate random numbers in a given range

Creating a christmas tree on linux terminal

Here is a script that,when executed, will draw a christmas tree using the characters choosen by the user on the linux terminal.

The script will prompt the user to enter the character using which the tree has to be drawn. Then it will prompt the user to enter two characters that will be used to decorate the tree. The last input it will ask for is the character using which the base of the tree has to be drawn.

chritstmas_tree.sh

#!/bin/bash trapi() { cols=`tput cols` start=$((cols/2)) # char=”*” char=”$3″ rows=$1 rows=$((rows+5)) # tput clear for((i=$1;i

Category: Linux | Comments Off on Creating a christmas tree on linux terminal

Creating an outline of triangle shape on linux terminal, using any characeter

This post is in response to the comment #2 in the post Creating a triangle of characters on terminal

The following script will create a blank triangle of characters on the linux terminal, but unlike the script in “” the triangle will be empty, i.e. only the outline has the characters chosen by the user and inside is left blank.

#!/bin/bash cols=`tput cols` start=$((cols/2)) echo “How many rows do you want” read rows echo “What character do you want to use” read char tput clear for((i=0;i

Category: Linux | Comments Off on Creating an outline of triangle shape on linux terminal, using any characeter

Linux script to find prime numbers in a range of numbers

In the post ” ” we saw how we can use the command factor to find whether a number is prime of not. We can extend the same script further to generate all the prime numbers in a given range of numbers.

To generate a range of numbers we can use the command “seq” . The usage of seq is shown in the post ” “.

We can use seq in a for loop to iterate over one number at time.

for mun in `seq 4 10` do echo $mun done

Save the script as seq_for.sh, give it execute permissions and run the script.

$ chmod 777 seq_for.sh $ ./seq_for.sh 4 5 6 7 8 9 10

Thus we can see that using seq along with for loop we can work on a range of numbers, one number at a time.

This script can be combined with the script in ” ” to generate all the prime numbers in a range of numbers.

We request the user to enter two numbers to indicate the lower and upper limits of the range of numbers between which the user wants to generate the prime numbers. The lower limit can not be 1 because the number 1 does not have any factors and the command “factor” does not return any thing for 1. Thus we need to make sure the user enters a number bigger than 1. If the user enters 1, then we will prompt the user again to enter number greater than 1.

while [ $low -eq 1 ] do echo “Enter the lower limit,greater than 1” read low done echo “Enter the upper limit” read upper

Then we pass these two numbers to seq in a for loop

for mun in `seq $low $upper`

In each iteration of the for loop we use the factor command to find out if a number is prime or not.

do ret=$(factor $mun | grep $mun | cut -d “:” -f 2 | cut -d ” ” -f 2) if [ “$ret” -eq “$mun” ] then echo “$mun is prime” fi done

The full script looks as below.

#! /bin/bash low=1 count=0 while [ $low -eq 1 ] do echo “Enter the lower limit,greater than 1” read low done echo “Enter the upper limit” read upper for mun in `seq $low $upper` do ret=$(factor $mun | grep $mun | cut -d “:” -f 2 | cut -d ” ” -f 2) if [ “$ret” -eq “$mun” ] then echo “$mun is prime” ((count++)) fi done echo -e “\n There are $count number of prime numbers”

Save the script as range_prime.sh,give it execute permissions and run it.

$ chmod 777 range_prime.sh $ ./range_prim.sh Enter the lower limit 2 Enter the upper limit 20 2 is prime 3 is prime 5 is prime 7 is prime 11 is prime 13 is prime 17 is prime 19 is prime There are $count number of prime numbers

Thus we can see the script is able to generate a list of all the prime numbers between 2 and 20.

Category: Linux | Comments Off on Linux script to find prime numbers in a range of numbers

Linux script to find prime numbers in a range of numbers

In the post ” ” we saw how we can use the command factor to find whether a number is prime of not. We can extend the same script further to generate all the prime numbers in a given range of numbers.

To generate a range of numbers we can use the command “seq” . The usage of seq is shown in the post ” “.

We can use seq in a for loop to iterate over one number at time.

for mun in `seq 4 10` do echo $mun done

Save the script as seq_for.sh, give it execute permissions and run the script.

$ chmod 777 seq_for.sh $ ./seq_for.sh 4 5 6 7 8 9 10

Thus we can see that using seq along with for loop we can work on a range of numbers, one number at a time.

This script can be combined with the script in ” ” to generate all the prime numbers in a range of numbers.

We request the user to enter two numbers to indicate the lower and upper limits of the range of numbers between which the user wants to generate the prime numbers. The lower limit can not be 1 because the number 1 does not have any factors and the command “factor” does not return any thing for 1. Thus we need to make sure the user enters a number bigger than 1. If the user enters 1, then we will prompt the user again to enter number greater than 1.

while [ $low -eq 1 ] do echo “Enter the lower limit,greater than 1” read low done echo “Enter the upper limit” read upper

Then we pass these two numbers to seq in a for loop

for mun in `seq $low $upper`

In each iteration of the for loop we use the factor command to find out if a number is prime or not.

do ret=$(factor $mun | grep $mun | cut -d “:” -f 2 | cut -d ” ” -f 2) if [ “$ret” -eq “$mun” ] then echo “$mun is prime” fi done

The full script looks as below.

#! /bin/bash low=1 count=0 while [ $low -eq 1 ] do echo “Enter the lower limit,greater than 1” read low done echo “Enter the upper limit” read upper for mun in `seq $low $upper` do ret=$(factor $mun | grep $mun | cut -d “:” -f 2 | cut -d ” ” -f 2) if [ “$ret” -eq “$mun” ] then echo “$mun is prime” ((count++)) fi done echo -e “\n There are $count number of prime numbers”

Save the script as range_prime.sh,give it execute permissions and run it.

$ chmod 777 range_prime.sh $ ./range_prim.sh Enter the lower limit 2 Enter the upper limit 20 2 is prime 3 is prime 5 is prime 7 is prime 11 is prime 13 is prime 17 is prime 19 is prime There are $count number of prime numbers

Thus we can see the script is able to generate a list of all the prime numbers between 2 and 20.

Category: Linux | Comments Off on Linux script to find prime numbers in a range of numbers