Problem
You have a text file that has empty lines, and you would like to remove them.
Solution
You can use awk in linux like the following to create a new file with the empty lines removed:
awk 'NF' file_with_blank_lines > file_without_blank_lines
Problem
You have a text file that has empty lines, and you would like to remove them.
Solution
You can use awk in linux like the following to create a new file with the empty lines removed:
awk 'NF' file_with_blank_lines > file_without_blank_lines
Problem
You have some databases in MySQL that contain dashes in their names, and when you try to use them (ie grant access to them), you get the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-db.* to 'username'@'%'' at line 1
Solution
To be able to use them, enclose the database name in backticks (`) like:
GRANT ALL on `databasename-db`.* to 'username'@'%'
Problem
You would like to find the files that contain some specific text, and would like to do it recursively (ie in a project folder), using something simpler than the find command.
Solution
You can use the following in your current top folder to search recursively, case-independent and by displaying the file number that the searched text appears, with the following:
grep -rin "TextToBeSearched" .
Problem
You would like to get a list of the available images in Digital Ocean, in order to be able to use them in creating your Terraform IAC script.
Solution
By installing the command line tool doctl, (instructions here), according to the documentation (after authenticating) you can run:
doctl compute image list
But the available images are not listed. In order to be list all the images you have to add the –public option (as described here) :
doctl compute image list --public
Problem
You are trying to install/remove a package but you always get an error message about linux message as above:
Errors were encountered while processing: linux-image-3.13.0-128-generic
Solution
Try the following:
rm -rf /var/lib/dpkg/info/linux-image-3.13.0-128-generic.* apt-get purge linux-image-3.13.0-128-generic
Problem
You would like to send the error output from a command or a script to both an error file and an email.
Solution
By using tee, you could do the following:
command_with_parameters 2>&1 | tee /log_file_name | mail -s 'Command error' me@mydomain.com
Problem
You would like to know the release of your CentOS server but the cat /etc/issue does not work.
Solution
Try with the following:
cat /etc/centos-release
or with:
cat /etc/redhat-release
Problem
You have a bash script that accepts parameter(s) but you want to give a default value for a missing parameter.
Solution
For example you have a script that accepts a parameter with the year and month (ie 201703), but you want to give it a default of two months ago if the parameter is missing.
#!/bin/bash
LM=$(date -d '2 month ago' +%Y%m)
YEARMONTH=${1:-${LM}}
echo $YEARMONTH
Problem
You are using CI/CD to deploy a Symfony application that has the appversion.yml configuration file, and you want to add the environment and a timestamp to it after deployment.
Solution
You can achieve this by creating and running a bash script like the following and passing the environment as a variable (ie script_name env) :
#!/bin/bash
# Script for adding the environment and time in deployment
# Needs the environment as a parameter
# DATE_CREATED=2017.06.07
# DATE_UPDATED=2017.06.08
# VERSION=1.01
CONF_PATH=/var/www/analyse/app/config
sed '/app.version/s/\(.*$\)/\1'" (${1}) $(date +%Y%m%d-%H%M)"'/g' $CONF_PATH/appversion.yml > $CONF_PATH/appversion_new.yml
mv $CONF_PATH/appversion.yml $CONF_PATH/appversion_bak.yml
mv $CONF_PATH/appversion_new.yml $CONF_PATH/appversion.yml
Problem
You would like to know the codename (release) name of your Debian/Ubuntu system. Running cat /etc/issue will give you the release version but not the number.
Solution
Run the following command to get your release name:
lsb_release -cs