Restart service on no linux logs output

Sometimes I have apps that suddenly stop working, however they don’t have PID output or I can’t start them via systemd or upstart due to convoluted requirements. Other times the app is on but it stops processing incoming queues due to various reasons. I need to make sure i have a mechanism in place to Restart service as needed. I’m going to describe how you can check for Linux logs output and if there is no log for X seconds then we restart the app! we check the log every X seconds and if in the past X seconds there is no movement we perform X function. Restart service script #!/bin/bash # simple script to check logs, if no entries have been made in 45 seconds restart set -x PATH=$PATH:/usr/sbin TS=$(date +%s) timer1=$(expr $TS – $(date +%s -r /path/to/some/file.log)) # make sure to set the log path here if [ “$timer1” -gt 45 ] then echo $timer1 echo “restarting service due to no activity for 45 seconds” sudo service mycoolservice restart # you can change this for something else such as sending email or even rebooting the machine. fi

Ubuntu & Bash tutorial & basic utilities

An introduction to the CLI (Command Line Interface) and Bash on Ubuntu Linux aka a bash tutorial The default shell that is installed on Ubuntu Linux is bash. Alternatives exist, but they’re beyond the scope of this tutorial (check our post here for more info on how to isntall a better alternative to bash called Zshell or zsh). Bash is available on almost all Linux distributions, so this tutorial will work on most Linux distributions as well. What is a shell? Simply put, the shell is a program that takes your commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix computer. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell. Bash is the most popular shell application for Linux, and is the default on Ubuntu and hundreds of other Linux distributions, Mac OS X, and soon Windows 10. The basics are: You type one or more command(s), hit enter, and it runs the command(s). Use the up/down arrows to go through your bash history. Ctrl+P also works Use Ctrl+R to search the history of commands used previously. Hitting tab will autocomplete commands. Instead of typing cd ~/myfolder1/ you can just type cd ~/my<tab> and it’ll either autocomplete fully or if there are still more folders (like my234 and myfolder1), it’ll show you your options. You can enter multiple commands by separating them with “;” or “&&”. ; allows commands […]

Why you should switch to ZShell ( zsh )

Why use ZShell It has some amazing features, but right out of the gate in no particular order: Context based tab completion that puts most others out there to shame. Shared history among tabs. Dynamic Load modules Spelling correction that out performs most others out there. Globbing that works on magic. I am positive of this. Themes that work wonders, there are tons of them out there and they fit everyone’s needs or just write your own! Global aliases I’m going to be an elitist and say bash is for the cavemen 😐 any machine you have a personal user account on: install zsh. life just became pretty… and pretty awesome. why zsh? well its powerful and configurable…. its awesome! and you can change a LOT about it and extend it via plugins. sudo apt-get install zsh curl git-core ruby wget –no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O – | sh this should switch you to zsh and install an awesome script for zsh. if not then do the next two steps. They can be repeated at will. Note where your zsh is, most likely /bin/zsh. which zsh chsh After that comes customization time! yay… etc. (pick a theme, I prefer dallas so) edit ~/.zshrc ZSH_THEME=”dallas” Heres my plugins, you can remove the ones you dont need plugins=(git ant cpanm debian github mercurial node npm svn) Install rvm : user$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) add the following to your ~/.zshrc [[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm more to come later.[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Alsa CLI Volume control

I couldn’t find the silly volume control in the system settings one day so i figured there had to be something I could use to control volume settings like mic boost without needing a gui or remembering names and numbers for the CLI. well there is and it’s so easy a caveman could do it (hah remember those ads….)…. so without further ado here’s a fun and great way to control your volume via Alsa CLI Volume control. type the following then use your arrows to move right/left and make the volume higher or lower by using up/down keys: alsamixer -c 0 the 0 at the end is the number of your device. if a system only has one device you will use 0. if you have two devices you can use 0 or 1. it tells you the name of the device currently being edited so you don’t give yourself a heart attack by changing the wrong volume. picture of the control is attached.   [et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”] [/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]

Cyanogenmod Gapps error with SetupWizard

I saw that CM13 is out and it brings Android 6.0.1 (r17) goodies such as the battery saving ‘doze’ functionality and new permissions model, alongside the usual set of CM features. I have an HTC m8 sitting around which I figure was due for a custom rom right about now, so I downloaded and install a copy of CM 13 from https://get.cm. everything went well as expected. I downloaded a copy of google apps from opengapps and installed it next and thats where things took a turn for the worse, as soon as I booted into CM i started getting errors of setup wizard being force closed over and over. I couldnt do anything but click the OK button over and over. So if you are getting a Cyanogenmod Gapps error this just may help you. I booted into TWRP and tried fixing permission with no luck on next boot into system. I tried re-flashing everything from a clean install again with same results. I saw that you could report the issue so I clicked the submit button and it let me see the actual error that was being thrown which looked partially like : AndroidRuntime: java.lang.RuntimeException: Unable to create application com.google.android.setupwizard.SetupWizardApplication: java.lang.SecurityException: addOnSubscriptionsChangedListener: Neither user 10069 nor current process has android.permission.READ_PHONE_STATE. luckily I had enabled debugging before I installed gapps. so I connected my phone to my computer, booted up ADB, check out my post on some basic ADB commands here if you need a refresher, and granted the permissions needed for the issue […]

Linux distribution info & kernel info

Do you have multiple vms and real machines you use for random testing, and small tasks? need to know what machine you are on? what kernel you are using? what the current Linux distribution info is? what OS version did you last install on here? and more such questions? well! we have some of the answers for you. well maybe not answers, but more like small tools so you can get the answers! Distribution info lsb_release -a on my ubuntu system it gives the following result : $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu Xenial Xerus (development branch) Release: 16.04 Codename: xenial On a debian system it gives the following result : # lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.4 (jessie) Release: 8.4 Codename: jessie If lsb_release -a doesn’t cut it for you then you can try cat /etc/issue as a result we see the following examples : # cat /etc/issue Debian GNU/Linux 8 \n \l $ cat /etc/issue Ubuntu Xenial Xerus (development branch) \n \l In some cases where you suspect you are on centos or redhat, maybe because you noticed the package versions are old enough to be used by columbus while sailing the open seas, then you can use either cat /etc/centos-release or cat /etc/redhat-release which will give you result such as : CentOS release 6.2 (Final) Kernel Info now as far as finding the kernel info goes you can get all the info you need via uname. $ uname -a […]