How Do You Troubleshoot Error Messages in a Bash Script?

Problem scenario
You run a shell or bash script but you receive an error message such as one of the following:

$’\r’: command not found
line:55 syntax error: unexpected end of file

Solution
Did you download the file from the internet directly to the Unix system? The root cause could be that there are invisible characters in the file.

If you can copy the content of the text into the Linux machine and have it run as a script,

 » Read more..

How Do You Troubleshoot the Bash Script Error “line 5: $’\r’: command not found”?

Problem scenario
You drafted a Bash script on a Windows computer.  You then uploaded it to Google Cloud Platform via a web browser feature.  When you run the bash script on a Linux server (e.g., in GCP), you get this error “line 5: $’\r’: command not found”.  You do not want to install dos2unix or any new packages.  What should you do?

Solution
The file needs to be modified or “cleaned up.” 

 » Read more..

How Do You Write a Hello World Program in Lua?

Problem scenario
You want to run a basic Lua program as a test.  What do you do?

Solution
Prerequisite

You must have installed the Lua compiler.  If you are using a CentOS/RHEL/Fedora server, try this link.

Procedures
1.  Create a file called contint.lua with the following line:
print(“This is a Hello World program”)

2.  Run it with this command: 

 » Read more..

How Do You Install the Lua Compiler on a CentOS/RHEL/Fedora Server?

Problem scenario
You want to run Lua programs on your Red Hat derivative distribution of Linux server (e.g., CentOS/RHEL/Fedora).  

Solution
1.  Make a script like this called lua.sh with the following lines:

yum -y install readline-devel gcc
curl https://www.lua.org/ftp/lua-5.3.5.tar.gz > /tmp/lua-5.3.5.tar.gz
mv /tmp/lua-5.3.5.tar.gz /opt/
cd /opt/
tar -xzvf lua-5.3.5.tar.gz
cd lua-5.3.5
sudo make linux test
echo “ENV=$ENV:/opt/lua-5.3.5/src/” >>

 » Read more..

How Do You Troubleshoot the Scala Error “No such file or class on class path”?

Problem scenario
You know Scala is installed because you use “man scala” and see the correct man page.  But when you try to find the version, you get an error.  Specifically you run this command:  scala version

You see this: “No such file or class on classpath: version.”  How do you find out what version of Scala you have installed?

Solution
Reboot the server.

 » Read more..

How Do You Install R on an Ubuntu Linux Instance of AWS?

Problem scenario
You are running Ubuntu Linux in AWS.  You want to install R. How do you do this?

Solution
(These directions below were adapted from this link.)

Prerequisite
Verify you have 1 GB of RAM.  Run this command:  sudo dmidecode -t 17 | grep Size

If you see 512 MB in the results of the above command,

 » Read more..

How Do You Install Scala on an Ubuntu Instance of AWS?

Problem scenario
You want to install Scala to an Ubuntu instance of AWS.  How do you do this?

Solution

Prerequisite
Verify you have 1 GB of RAM.  Run this command:  sudo dmidecode -t 17 | grep Size

If you see 512 MB in the output, then you will not be able to get Scala installed.  You will need an AWS instance with a flavor that has 1 GB of RAM or more. 

 » Read more..

How Do You Install Scala on a RHEL Instance of AWS?

Problem scenario
You want to install Scala to a Red Hat Enterprise Linux instance of AWS.  How do you do this?

Solution
1.  Install Java:  sudo yum -y install java-1.8*

2.  Log off and log back on.

3.  Run these three commands:
curl https://bintray.com/sbt/rpm/rpm | sudo tee /etc/yum.repos.d/bintray-sbt-rpm.repo
sudo yum -y install sbt
sbt new scala/hello-world.g8

4. 

 » Read more..

Using Bash How Do You Replace a Line in a File by Its Line Number?

Problem scenario
On your Linux server you know one line in a file needs to be replaced.  You can identify the file by its line number.  You have a string or pattern you want to be inserted where this line is. How do you do this with Bash?

Solution
To replace all the content of line 15 of foobar.txt with “Hello World” run this command:

perl -i -pe ‘s/.*/Hello World/ if $.==15’ foobar.txt

For something more advanced,

 » Read more..

Perl Script Debugging

Problem scenario:  You are running a Perl program and getting an error “syntax error at cool.pl line x, near …
Global symbol “$foo” requires explicit package name at cool.pl line x…”

Solution:  Find line x – 1, that is, the line before x.  This line may not have a semicolon.  Semicolons are not needed if the Perl script is one line.  Semicolons are not needed for “sub main” declaration lines with a line with just a brace (either “{” or “}”). 

 » Read more..