GNU/Linux


Downgrade texinfo on CentOS 7.0 (64bit) to version 4.13

Recently we had to download texinfo from version 5.1 to any version less than version 5 series.
We used texinfo version 4.13 which is the latest in the version 4 series.

We were trying to compile some tools using an older version of gcc. Instead of using 4.8.5, we used 4.8.2 to achieve our goal and that caused a problem with some .texi files.

Methodology


#Making sure we are not missing any 32bit libraries since we are on a 64bit machine
yum install glibc.i686 ncurses-libs.i686;
#Download the source code
wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.13.tar.gz;
#Extract the files
tar -zxf texinfo-4.13.tar.gz;
#Navigate to the folder
cd texinfo-4.13;
#Configure the installation and make all necessary checks
./configure;
#Build
make;
#Install
sudo make install;


Downgrade gcc on CentOS 7.0 (64bit) to version 4.8.2

Recently we had to download gcc from version 4.8.5 to 4.8.2.

We were trying to compile some tools and they required using that older version of gcc.
To compile the old version of the gcc we used the version version that was shipped with the distribution.

Methodology

#Making sure we are not missing any 32bit libraries since we are on a 64bit machine
yum install glibc.i686 ncurses-libs.i686;
#Download the source code
wget http://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.gz;
#Extract the files
tar -xvf gcc-4.8.2.tar.gz;
#Navigate to the folder
cd gcc-4.8.2/;
#Make sure we have all dependencies met
./contrib/download_prerequisites;
#Configure the installation and assign the installation folder to be /usr/local/gcc/4.8.2. Finally make all necessary checks before compilation.
./configure --prefix=/usr/local/gcc/4.8.2;
#Build
make;
#Install
sudo make install;

Bash: Check if file is found and contains data

The following code will check if the file described by variable FILENAME exists and has data.

if [ ! -f "$FILENAME" ]; then

    echo "Error: '$FILENAME' file not found.";
else

    if [ ! -s "$FILENAME" ]; then

        echo "Error: '$FILENAME' file is empty.";
    else

        echo "Info: '$FILENAME' file found and contains data.";
    fi
fi

Convert a list of integers from MySQL to a Bash array

The following code will connect to a MySQL server, it will get a list of integers and convert the results to a bash array that will be iterated using a for loop and they will be printed using zero padding.


IDS_RAW=$(mysql --user="myuser" --password="mypass" --host="db.example.com" --database="mydb" --batch --compress --skip-column-names --execute="
  SELECT
    Id
  FROM
    Users
  WHERE
    Status = 0;
");

OLDIFS=$IFS;
IFS=$'\n' command eval;
'IDS=($IDS_RAW)';
IFS=$OLDIFS;

echo "Will process the following user IDs '${IDS[@]}'";

for ID in "${IDS[@]}"; do
  LEADING_ZERO=$(printf %08d $ID);
  echo "ID $LEADING_ZERO";
done;