Archive for the ‘ Linux ’ Category

Author : beriba | 03/27/2018
#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/opt/project/project.jar
PID_PATH_NAME=/tmp/${SERVICE_NAME}-pid
LOG_FILE=/var/log/${SERVICE_NAME}.log
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup java -jar $PATH_TO_JAR >> $LOG_FILE 2>&1&
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup java -jar $PATH_TO_JAR >> $LOG_FILE 2>&1&
                        echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac
Author : beriba | 03/25/2018
tr ' ' "\n" < FILE | grep "string_you_want_to_count" | wc -l
Author : beriba | 09/16/2016

Installing agilo error:

protagonist@1.5.0 install: `node-gyp rebuild`

Installing protagonist error:

gyp: Call to 'node -e "require('nan')"' returned exit status 127 while in binding.gyp. while trying to load binding.gyp

Solution:

sudo apt-get install nodejs-legacy

Do it even if you have nodejs installed!

Author : beriba | 08/08/2016
sudo apt-get install exfat-fuse exfat-utils

Then just mount exFAT device.

Author : beriba | 02/01/2014

Using virtual machines is a very common practice. I’ll not tell you here the pros and cons of using them because it’s not the point of this post. One of the most popular VM tools is VirtualBox. While using linux VM you sometimes need to share some data between host and VM. Of course VirtualBox has a functionality to do that. From host (assuming that it is Windows) this folder is instantly accessible. But from VM this folder is only accessible by root. Adding sudo to every cp or any other command using shared folder isn’t what we really want. There is a solution. You just need to add your user to vboxsf group. You can do that by executing

sudo usermod -a -G vboxsf myusername

But that’s not everything. Now you just have to re-login (or reboot). But sometimes there are reasons to not reboot the VM. There’s also solution for that. You just have to do an explicit login.

su - myusername

There’s only one thing you have to remember. Until doing a re-login, you have to do an explicit login in every terminal session you open.

Author : beriba | 10/13/2012

To install phpmyadmin just execute this command:

sudo apt-get install phpmyadmin

Then you need to go to

http://localhost/phpmyadmin


PhpMyAdmin should now work. But if the above url gives you an error:

Not Found
The requested URL /phpmyadmin was not found on this server.

you need to check two things.
1. Open file:

/etc/phpmyadmin/apache.conf

and look for alias /phpmyadmin. It should look like this

Alias /phpmyadmin /usr/share/phpmyadmin

2. Check directory:

/etc/apache2/conf.d

There should be a file phpmyadmin.conf which is a symlink to

/etc/phpmyadmin/apache.conf

If it’s not there, create it with this command:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf

After this, you just need to restart the server and enjoy your phpmyadmin installation.

Author : beriba | 10/11/2012

This will be just a quick tip. If you want to change device/partition label in linux you just have to execute this command

sudo e2label <device> <label>

For example:

sudo e2label /dev/sda1 projects

Easy.

Author : beriba | 08/20/2012

To track newly added lines to file in Linux you can use command

tail -f filename.txt

It will show you every line added at the end of the filename.txt, exactly when it will be added to this file. It is very useful to make some new lines (after executing the command) to separate existing content from the one that will show up later. But don’t worry. Those new lines won’t be added to file.