Thursday, March 31, 2016

Rotating wallpapers

I got the wallpaper to change when I log on.  Minor fix to the command when starting up.  You start with 'Preferences' then pick 'Default applications for LXSessions'.  Click on the Autostart and create an entry like shown in the screen print.
LXSession settings


Shell command to rotate wallpaper





I then followed this up by seeing if I can put it into cron.  I did 'cron -e' from a command window and set it up to run every minute so I can see if would work.  Minutes passed and nothing happened.  I put in debug code to get the return code from pcmanfm and put it to a file.  Looking at the file I could see a return code of 1 so I knew that there was an error somewhere.  I check on-line and found an answer in stackoverflow.  I made a minor change in my script and it worked!  I reset cron to update it every 10 minutes and it still works.
cron settings to change wallpaper every 10 minutes

Bash script to change wallpaper

Monday, March 28, 2016

LINUX Bash Script skeleton code

I have been writing very simple Bash scripts for several years.  They are not complex, but, they help me automate tasks at home and work.  If I have to do something more than once I prefer to have a script automate that task. Over the years I have found that there are a lot of excellent on-line sites with information that helped me do my scripts.

From time-to-time this blog will be updated with new/updated skeleton script.

One site that I like is for color in Bash echo commands and they helped me when I was starting my use of color in scripts.  Most of my scripts don't need color, but, now and then I like to highlight something.  UBUNTU has a great forum area and I found a very nice script that allows me to quickly and easily change my background image. The link is here.

One of the first tasks I do with a new machine using LINUX and Z/OS Unix is to create a script library and place my skeleton bash template in that library.  I won't post the one from work as that is specific to the Z/OS environment and the client I work for.  The one I am posting is my personal template. When I find that I am using a piece of bash code on a regular basis I put it into the template and make it easier for me to find that one piece in the future.

My skeleton bash script is below.  I try to work with a basic naming standard.  User defined variables start with "u" and subroutines start with "z".  Everyone has their preferences, but, this is one I have been using for years and I am comfortable with it.  Version is showing as one as I finally got around to putting comments in and I figured that 1.00.00 is a good place to start.

START OF BASH SCRIPT


#! /bin/bash

# This is a skeleton script that has some of my bash codes commonly used
# in my scripts.
#
# Version:  1.00.00 - 2016/03/28 - TPT.  Initial version.
#

# ANSI Colors
zSetANSI() {

# Foreground colors:
    uFGBK="\033[30m";   #Black
    uFGLRD="\033[31m";  #Low  Red
    uFGHRD="\033[91m";  #High Red
    uFGLGR="\033[32m";  #Low  Green
    uFGHGR="\033[92m";  #High Green
    uFGLYW="\033[33m";  #Low  Yellow
    uFGHYW="\033[93m";  #High Yellow
    uFGLBU="\033[34m";  #Low  Blue
    uFGHBU="\033[94m";  #High Blue
    uFGLMG="\033[35m";  #Low  Magenta
    uFGHMG="\033[95m";  #High Magenta
    uFGLCY="\033[36m";  #Low  Cyan
    uFGHCY="\033[96m";  #High Cyan
    uFGHGY="\033[37m";  #High Gray
    uFGLGY="\033[90m";  #Low  Gray
    uFGWT="\033[97m";   #White

# Background colors:   
    uBGBK="\033[40m";   #Black
    uBGLRD="\033[41m";  #Low  Red
    uBGHRD="\033[101m"; #High Red
    uBGLGR="\033[42m";  #Low  Green
    uBGHGR="\033[102m"; #High Green
    uBGLYW="\033[43m";  #Low  Yellow
    uBGHYW="\033[103m"; #High Yellow
    uBGLBU="\033[44m";  #Low  Blue
    uBGHBU="\033[104m"; #High Blue
    uBGLMG="\033[45m";  #Low  Magenta
    uBGHMG="\033[105m"; #High Magenta
    uBGLCY="\033[46m";  #Low  Cyan
    uBGHCY="\033[106m"; #High Cyan
    uBGLGY="\033[47m";  #Low  Gray
    uBGHGY="\033[107m"; #High Gray

# Underline:
    uFGULINE="\033[4m";
   
# Blink:
    uFGBLINK="\033[5m";
   
# Reset all:   
    uFGRESET="\033[0m"
}


#
#  Get the system clock and set to a variable.
#

zGetDATE() {

# System date.  For all date options type date --h on command line.

    uSYSYY=$(date +%Y);
    uSYSMM=$(date +%m);
    uSYSDY=$(date +%d);
    uSYSDT=$uSYSYY$uSYSMM$uSYSDY;
   
    uSYSHH=$(date +%H);
    uSYSMIN=$(date +%M);
    uSYSSEC=$(date +%S);
    uSYSTM=$uSYSHH$uSYSMIN$uSYSSEC;
   
    uSYSJDT=$(date +%j);
    uSYSWK=$(date +%W);
    uSYSDOW=$(date +%w);
    uSYSDAY=$(date +%A)   
    uSYSMTH=$(date +%B)
}

# ============================================================
# END OF ALL SUBROUTINES FOR THIS SCRIPT.
# ============================================================

zSetANSI;
zGetDATE;

# Define the working variable for return codes:
uRC=0;

# Get current directory name
uDir=$( cd "$( dirname "$0" )" && pwd);

# Get process ID
uProcID=$$


#  Now echo out the stuff to the console:

clear;
echo "${uFGHRD}Process Information${uFGRESET}";
echo ;
echo "  ${uFGLGR}Directory........: " $uFGHGR $uDir;
echo "  ${uFGLGR}Process id.......: " $uFGHGR $uProcID;
echo "  ${uFGLGR}Directory........: " $uFGHGR $LOGNAME;
echo ;
echo $uFGHRD;
echo "Date information:" $uFGRESET;
echo "  ${uFGLYW}uSYSDT...........: " $uFGHYW $uSYSDT;
echo "  ${uFGLYW}uSYSTM...........: " $uFGHYW $uSYSTM;
echo "  ${uFGLYW}uSYSJDT..........: " $uFGHYW $uSYSJDT;
echo "  ${uFGLYW}uSYSWK...........: " $uFGHYW $uSYSWK;
echo "  ${uFGLYW}uSYSDOW..........: " $uFGHYW $uSYSDOW;
echo "  ${uFGLYW}uSYSDAY..........: " $uFGHYW $uSYSDAY;
echo "  ${uFGLYW}uSYSMTH..........: " $uFGHYW $uSYSMTH;

echo $uFGRESET;
echo $uFGHYW;
echo "ANSI Foreground color codes:" $uFGRESET;
echo "  RED..............: ${uFGLRD}Low ${uFGHRD}HIGH" $uFGRESET;
echo "  GREEN............: ${uFGLGR}Low ${uFGHGR}HIGH" $uFGRESET;
echo "  YELLOW...........: ${uFGLYW}Low ${uFGHYW}HIGH" $uFGRESET;
echo "  BLUE.............: ${uFGLBU}Low ${uFGHBU}HIGH" $uFGRESET;
echo "  MAGENTA..........: ${uFGLMG}Low ${uFGHMG}HIGH" $uFGRESET;
echo "  CYAN.............: ${uFGLCY}Low ${uFGHCY}HIGH" $uFGRESET;
echo "  GRAY.............: ${uFGLGY}Low ${uFGHGY}HIGH" $uFGRESET;

echo ;
echo $uFGHYW;
echo "ANSI Background color codes:" $uFGRESET;
echo "  RED..............: ${uBGLRD}Low ${uBGHRD}HIGH" $uFGRESET;
echo "  GREEN............: ${uBGLGR}${uFGBK}Low ${uBGHGR}HIGH" $uFGRESET;
echo "  YELLOW...........: ${uBGLYW}${uFGBK}Low ${uBGHYW}HIGH" $uFGRESET;
echo "  BLUE.............: ${uBGLBU}Low ${uBGHBU}${uFGBK}HIGH" $uFGRESET;
echo "  MAGENTA..........: ${uBGLMG}Low ${uBGHMG}${uFGBK}HIGH" $uFGRESET;
echo "  CYAN.............: ${uBGLCY}Low ${uBGHCY}${uFGBK}HIGH" $uFGRESET;
echo "  GRAY.............: ${uBGLGY}${uFGBK}Low ${uBGHGY}HIGH" $uFGRESET;


echo ;
echo $uFGHYW;
echo "ANSI Other color codes:" $uFGRESET;
echo ;
echo "  UNDERLINE........: ${uFGULINE}Underline" $uFGRESET;
echo "  BLINK............: ${uFGBLINK}Blink" $uFGRESET;
echo ;
echo "Script finishing with return code: " $uRC;


exit $uRC;

# ----------  END OF SCRIPT ----------


Saturday, March 26, 2016

A week in and tweaking LUBUNTU to fit

Now that I have been using LUBUNTU for a week I am now tweaking the system to make it easier for me.  If there is something I do more than once I want to automate it, even if it is a one line command.

I created a couple of folders and dropped in shortcuts or scripts of what I do.  Nothing earthshaking, but, they make my life easier.  One folder are one line commands.  XTERM with settings I prefer to work with, midnight commander and top.  After I get it all tweaked to the way I want the next thing is to learn how to add these to the menu.  Can I improve the scripts, yes!  This is just the start.

My Tools folder for building desktop shortcuts

Desktop setup for midnight commander

Midnight commander with font/colors I prefer
Midnight commander
 
In windows you can do something similar with shortcuts, but, I like linux as I can tweak things to work in exactly the way I want with simple text files and bash.  As things go on I will be building more and more tools to automate my work.  I do this where I work and I have a large toolkit there that automates almost all of my mainframe work that I have to do on a regular basis.

Update 1 - 2016/03/27:

Yay, I found out how to add entries to the menu.  Right now it is to the Other folder, but, that is a good step.  I had to copy my applications to */.local/share/applications and they showed up in menu.


My Menu now shows my apps

~/.local/share/applications

Update 2 - 2016/03/28:

Minor update, I added KATE to my editors.  I like it as it is small, fast, light and does what I need a code editor to do.