Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script to check ubuntu version and then copy files

I am new to shell script programming. I want to write a simple shell script to check the ubuntu version installed in the system; if the version is greater than or equal to version 12 then copy some files, and if it's less then copy some other files.

like image 614
arun arun Avatar asked Oct 23 '25 16:10

arun arun


2 Answers

The lsb_release -rs command lets us determine the Ubuntu version, we could use it like this:

if [[ $(lsb_release -rs) == "18.04" ]]; then # replace 8.04 by the number of release you want

       echo "Compatible version"
       #Copy your files here
else
       echo "Non-compatible version"
fi

`` (enclosing backticks) is non-POSIX and deprecated.

like image 91
Pieter Avatar answered Oct 25 '25 07:10

Pieter


cat /etc/issue.net |  awk '{x=2 ; if (substr($x,0,3) == '12') {system("cp <src> <dest>") } else {system("cp <src> <dest>") }}'

cat /etc/issue.net will show 3 fields out of which 2nd field is version no.

by substr we check the first two digit if it is version 12 then by system command inside awk we can copy certain files from a particular src to dest.

like image 44
WellNGood Avatar answered Oct 25 '25 07:10

WellNGood