Unable to upgrade Perl 5.8 to 5.16 in RHEL 7.6 - linux

6 and am unable to upgrade my machine from 5.8.9. When I install using yum install perl, it says successfully installed, but when I check version it is still the old one. I need the version to be 5.10 or above. Following are the details:
bash$ cat /etc/*release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.6 (Maipo)"
bash$
bash$ yum info perl
Name : perl
Arch : x86_64
Epoch : 4
Version : 5.16.3
Release : 294.el7_6
Size : 22 M
Repo : installed
From repo : rhel-7-server-rpms
Summary : Practical Extraction and Report Language
URL : http://www.perl.org/
bash$ perl -v
This is perl, v5.8.9 built for x86_64-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2008, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
bash$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin:/a
bash$ whereis perl
perl: /usr/bin/perl /usr/local/bin/perl5.6 /usr/local/bin/perl5.8 /usr/local/bin/perl /auto/usrcisco-linux-rhel7.0-x86-64/packages/perl/perl-5.8.9/bin/perl /usr/share/man/man1/perl.1.gz
Solution:
bash$ whereis perl5.16.3
perl5.16: /usr/bin/perl5.16.3
bash$ ll | grep -i perl
lrwxrwxrwx. 1 root root 19 Jul 2 2019 perl -> /usr/ravi/bin/perl
bash$ sudo ln -s -f /usr/bin/perl5.16.3 perl
bash$
bash$ ll | grep -i perl
lrwxrwxrwx 1 root root 19 Feb 22 17:49 perl -> /usr/bin/perl5.16.3
bash$ perl --version
perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 39 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall
Thanks in Advance for any input

bash$ whereis perl5.16.3
perl5.16: /usr/bin/perl5.16.3
bash$ ll | grep -i perl
lrwxrwxrwx. 1 root root 19 Jul 2 2019 perl -> /usr/ravi/bin/perl
bash$ sudo ln -s -f /usr/bin/perl5.16.3 /usr/bin/perl
bash$
bash$ ll | grep -i perl
lrwxrwxrwx 1 root root 19 Feb 22 17:49 perl -> /usr/bin/perl5.16.3
bash$ perl --version
perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 39 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall

Related

Bash script automation checking if certain version of app is installed or not [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to automate some basics in my Linux Server, I would like to check if the certain version of application like git, python or some other apps are installed or not, if installed than update to latest stable version. Here is my script and it seems I'm missing something:
#!/bin/sh
CURRENT_OS=$(hostnamectl | awk '/Operating/ { print $3 }')
CURRENT_PY=$(python3 -V | awk '{ print $2 }')
CURRENT_GT=$(git --version | awk '{ print $3 }')
if [ $CURRENT_OS=~"Fedora" || $CURRENT_OS=~"Centos" || $CURRENT_OS=~"Red Hat" ]; then
echo "➥➥➥ Current System Is Based On $CURRENT_OS"
sudo dnf clean all
sudo dnf -y upgrade
if [ $CURRENT_PY!="Python 3.8" ]; then
echo "➥➥➥ Installing Latest Python Release"
sudo dnf -y install python3.8
else
echo "➥➥➥ Latest Python Release Found In System"
fi
fi
Also is there any chance to swap output of command python3 -V | awk '{ print $2 }' to 3.8 instead of 3.8.5?
And also how can I refactor the OS release check so either is Red Hat, Centos or Fedora?
You can filter the the Python version using sed, e.g.
python3 -V | awk '{ print $2 }' | sed 's/\([0-9]*\.[0-9]*\).*/\1/'
The question about the OS release check is not clear. If you only want to have the correct distribution name in the output you can use e.g.
echo "➥➥➥ Current System Is Based On $CURRENT_OS"
Edit:
This was not meant as a fix for a "typo" but my (possibly wrong) interpretation of the unclear question.
If you want to find a common criteria for Red Hat, Centos or Fedora, the existence of a file /etc/redhat-release might be an indication for this family of distributions as /etc/debian_version is an indication for a Debian based distribution (including e.g. Ubuntu). That means a check like
if [ -e /etc/redhat-release ]; then
echo "➥➥➥ Current system seems to be a distribution of the RedHat family"
# ...
fi
might do what you need.
Please clarify the question.
If you are only dealing with CentOS/Fedora/Red Hat you can use /etc/redhat-release to find which distribution it is, or also lsb_release -i instead of hostnamectl.
Also on Fedora and CentOS you usually also have fedora-release and centos-release files, in addition to redhat-release.
You can also grep ID from /etc/os-release.
[user#redhat8 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.1 (Ootpa)
[user#redhat8 ~]# lsb_release -i
Distributor ID: RedHatEnterprise
[user#redhat8 ~]# ls -l /etc/*release
-rw-r--r--. 1 root root 501 Sep 25 2019 /etc/os-release
-rw-r--r--. 1 root root 45 Sep 25 2019 /etc/redhat-release
lrwxrwxrwx. 1 root root 14 Sep 25 2019 /etc/system-release -> redhat-release
[user#redhat8 ~]# grep -w ID /etc/os-release
ID="rhel"
[user#centos7 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root#centos7 ~]# lsb_release -i
Distributor ID: CentOS
[user#centos7 ~]# ls -l /etc/*release
-rw-r--r--. 1 root root 38 Nov 23 2018 /etc/centos-release
-rw-r--r--. 1 root root 393 Nov 23 2018 /etc/os-release
lrwxrwxrwx. 1 root root 14 Apr 15 09:05 /etc/redhat-release -> centos-release
lrwxrwxrwx. 1 root root 14 Apr 15 09:05 /etc/system-release -> centos-release
[user#centos7 ~]# grep -w ID /etc/os-release
ID="centos"
[user#Fedora ~]$ cat /etc/redhat-release
Fedora release 32 (Thirty Two)
[user#Fedora ~]$ lsb_release -i
Distributor ID: Fedora
[user#fedora ~]$ ls -l /etc/*release
lrwxrwxrwx. 1 root root 25 Jun 5 22:00 /etc/fedora-release -> ../usr/lib/fedora-release
lrwxrwxrwx. 1 root root 21 Jun 5 22:00 /etc/os-release -> ../usr/lib/os-release
lrwxrwxrwx. 1 root root 14 Jun 5 22:00 /etc/redhat-release -> fedora-release
lrwxrwxrwx. 1 root root 14 Jun 5 22:00 /etc/system-release -> fedora-release
[user#fedora ~]$ grep -w ID /etc/os-release
ID=fedora
You will need to have redhat-lsb-core package installed to have lsb_release command on Red Hat based distributions.

why sh softlink to bash doesn't work? [duplicate]

I have a shell script which uses process substitution
The script is:
#!/bin/bash
while read line
do
echo "$line"
done < <( grep "^abcd$" file.txt )
When I run the script using sh file.sh I get the following output
$sh file.sh
file.sh: line 5: syntax error near unexpected token `<'
file.sh: line 5: `done < <( grep "^abcd$" file.txt )'
When I run the script using bash file.sh, the script works.
Interestingly, sh is a soft-link mapped to /bin/bash.
$ which bash
/bin/bash
$ which sh
/usr/bin/sh
$ ls -l /usr/bin/sh
lrwxrwxrwx 1 root root 9 Jul 23 2012 /usr/bin/sh -> /bin/bash
$ ls -l /bin/bash
-rwxr-xr-x 1 root root 648016 Jul 12 2012 /bin/bash
I tested to make sure symbolic links are being followed in my shell using the following:
$ ./a.out
hello world
$ ln -s a.out a.link
$ ./a.link
hello world
$ ls -l a.out
-rwx--x--x 1 xxxx xxxx 16614 Dec 27 19:53 a.out
$ ls -l a.link
lrwxrwxrwx 1 xxxx xxxx 5 May 14 14:12 a.link -> a.out
I am unable to understand why sh file.sh does not execute as /bin/bash file.sh since sh is a symbolic link to /bin/bash.
Any insights will be much appreciated. Thanks.
When invoked as sh, bash enters posix
mode after the startup files are read. Process substitution is not recognized in posix mode. According to posix, <(foo) should direct input from the file named (foo). (Well, that is, according to my reading of the standard. The grammar is ambiguous in many places.)
EDIT: From the bash manual:
The following list is what’s changed when ‘POSIX mode’ is in effect:
...
Process substitution is not available.

Locale does not work in Perl on FreeBSD

The following does work (outputs a message in Russian about my attempt to open an nonexistent directory) for perl5 (revision 5 version 22 subversion 2) on Debian Linux (Bash):
LANGUAGE=ru_RU.UTF-8 perl -Mstrict -Mwarnings -Mlocale -e 'opendir my $fh, "afdsfd"; print $!, "\n"'
But on FreeBSD perl5 (revision 5 version 20 subversion 3) it prints the message in English. Why does it not work on FreeBSD?
On FreeBSD:
$ locale -a | grep ru
ru_RU.CP1251
ru_RU.CP866
ru_RU.ISO8859-5
ru_RU.KOI8-R
ru_RU.UTF-8
I've found that Russian messages on FreeBSD 10.3-RELEASE work with KOI8-R, but do not work with UTF-8.
Example:
perl -Mstrict -Mwarnings -MPOSIX -e 'setlocale(POSIX::LC_ALL, "ru_RU.KOI8-R"); opendir my $fh, "afdsfd"; print $!, "\n"' | iconv -f KOI8-R -t UTF-8

getting SW version by bash script for uninstall preinstalled software/notifying easily by assigning variable to it. Please share more ideas

Please share more ideas to get software version from bash command and use it as variable later.
su --version
su (GNU coreutils) 5.97
Copyright etc.
and create variable of the result of it.
Something like I tried below.
su --version >/tmp/temp.txt
if [ -f /tmp/temp.txt ]; then
elv=`cat /tmp/temp.txt | gawk 'BEGIN {FS="(GNU coreutils)"} {print $2}' | gawk 'BEGIN {FS="."} {print $1}'`
#Version String. Just a shortcut to be used later
els=el$elv
else
echo "Unable to determine version. I can't continue"
exit 1
fi
if [ `rpm -qa | egrep -c -i "^mysql-"` -gt 0 ]; then
cat << EOF
It appears that the distro-supplied version of MySQL is at least partially installed,
or a prior installation attempt failed.
Please remove these packages, as well as their dependencies (often postfix), and then
retry this script:
$(rpm -qa | egrep -i "^mysql-")
EOF
exit 1
fi

How do I find the latest date folder in a directory and then construct the command in a shell script?

I have a directory in which I will have some folders with date format (YYYYMMDD) as shown below -
david#machineX:/database/batch/snapshot$ ls -lt
drwxr-xr-x 2 app kyte 86016 Oct 25 05:19 20141023
drwxr-xr-x 2 app kyte 73728 Oct 18 00:21 20141016
drwxr-xr-x 2 app kyte 73728 Oct 9 22:23 20141009
drwxr-xr-x 2 app kyte 81920 Oct 4 03:11 20141002
Now I need to extract latest date folder from the /database/batch/snapshot directory and then construct the command in my shell script like this -
./file_checker --directory /database/batch/snapshot/20141023/ --regex ".*.data" > shardfile_20141023.log
Below is my shell script -
#!/bin/bash
./file_checker --directory /database/batch/snapshot/20141023/ --regex ".*.data" > shardfile_20141023.log
# now I need to grep shardfile_20141023.log after above command is executed
How do I find the latest date folder and construct above command in a shell script?
Look, this is one of approaches, just grep only folders that have 8 digits:
ls -t1 | grep -P -e "\d{8}" | head -1
Or
ls -t1 | grep -E -e "[0-9]{8}" | head -1
You could try the following in your script:
pushd /database/batch/snapshot
LATESTDATE=`ls -d * | sort -n | tail -1`
popd
./file_checker --directory /database/batch/snapshot/${LATESTDATE}/ --regex ".*.data" > shardfile_${LATESTDATE}.log
See BashFAQ#099 aka "How can I get the newest (or oldest) file from a directory?".
That being said, if you don't care for actual modification time and just want to find the most recent directory based on name you can use an array and globbing (note: the sort order with globbing is subject to LC_COLLATE):
$ find
.
./20141002
./20141009
./20141016
./20141023
$ foo=( * )
$ echo "${foo[${#foo[#]}-1]}"
20141023

Resources