• Linux
  • March 2018
    M T W T F S S
    « Feb    
  • Meta

  • Follow me on Twitter

  • Advertisements


This evening I wrote a short bash script to pull the necessary information for the battery, CPU, and network interfaces and writes the information to a text file. It combines the commands listed on my Conky Configuration page into a single script and provides the user with a text file from which to copy the device names and paste where necessary.

I had initially planned to include it at the beginning of the script to install my conky configuration but I’m thinking it might work better as a stand alone script. I’ll pretty up conkyinfo.sh and make it available from my Dropbox. I may still incorporate it into myconky.sh. That’s still a work in progress.


Another Conky update

While using the All-in-One System Rescue Toolkit to wipe a hard drive on an old laptop, I noticed its display of system information on the desktop which included the OS version. I wondered if I could do that in Conky. Well, it can be done.

I found what I needed in the Kubuntu Forums .  The pre_exec command did not work on my Mint 18.1 system but I found that by replacing it with execi 60 did the trick. It refreshes the release information every 60 seconds but I can live with that.

This worked in Mint 17.x:
${pre_exec lsb_release -d | cut -f 2| tr “[:upper:]” “[:lower:]”}

I had change the pre_exec command to execi xx in Mint 18:
${execi 60 lsb_release -d | cut -f 2| tr “[:upper:]” “[:lower:]”}

I added the lines in the SYSTEM section of my script just below the line that displays the kernel information. I commented out the line with the pre_exec command since I’m using Mint 18.x (Ubuntu 16.04). I didn’t test the execi 60 line in 17.x but it should work but both are available.

My downloadable script is available through my Conky Configuration page.

cpmvpic script

Last April I created cpmvpic.sh (copy move picture), a bash script that copies files from a temporary folder to my Dropbox so I can access them on my other systems. It also moves the file out of the temporary folder into a particular folder on my main system. At the time I used the images in html documents so later I added functionality to copy the document containing the image to my Dropbox. Then several months later I began creating the documents in LibreOffice (odt) format so I disabled that feature.

Today I made some changes to the directory structure for the Dropbox copies of the files so I modified the script to reflect those changes. I also renamed some of the variables to give them more meaningful names and re-enabled the copying of the target document.

The script uses the name of the image file, the 2-digit month, and the 4-digit year to build the necessary paths and document file names from base path names. It checks for the correct number of arguments and the validity of the paths and file names. If an error is detected, it displays an appropriate error message and the correct syntax, then exits.

I use this script for a specific series of documents which use the same naming convention in a particular set of folders. Although it’s a specialized script, it could be easily adapted for similar file copy operations.


Scripting again

Often when I download images from my digital camera or my mobile phone, or other files from the Internet, I’ll often find that the file extensions will be in all caps and my preference is to have them lower case.

I came across the rename command a while back and found it quite useful but found the syntax a bit difficult to remember. I’d been thinking about creating a bash script to make using the command a little easier and realized that it would be good if I could apply it to several file extensions I’m likely to encounter. This morning a wrote a simple script taking the file extension I wished to rename as an argument and using case statements to select the appropriate rename syntax. I also included a function to be called if no argument or an incorrect argument was entered.

After successfully testing it on a series of test files, I ran it in some folders in my ~/Pictures directory that had files with the .JPG extension and all the extensions were changed to .jpg. The script works well and at a later time I’ll probably add checks to handle duplicate file names, should they occur. As it is the rename command won’t change the file name if a duplicate will result.


A little scripting

About a month ago I created a little bash script to copy an image file from a temporary folder to my journal folders on my PC and Dropbox. The original script worked well enough but it lacked error checking plus I knew I’d have to eventually make changes to use it with next years folders.

The original script took two arguments from the command line, the file to be copied and moved, and the month which designated the appropriate folder. I added a third argument, the four-digit year used in the parent folder. Since the year would be incorporated with in the folder names and the month at the end, I changed the method used to build the folder names using the += operator.

In creating the tests to check the validity of the file to be manipulated and the existence of the created folders, I found it useful to create a function that would print the proper syntax should any of the tests fail.

I also developed a test that after the copy and the move operations checks for the existence of the file in each of the destination folders and displays the operation’s success or failure.

This was a good scripting exercise for me and the first time I’ve used a function in a utility script. I’d like to improve my scripting skills but the tutorials I have have given an elementary understanding but provide little in the way of practical examples and the usage of functions. I’ll be looking for other tutorials to advance my knowledge.



Conky config page updated

I think I’ve done enough with my conky configuration and installation for now. I successfully installed and configured conky on two Peppermint 7 Linux installations, on a virtual machine on my main desktop and on a PC I’d built a few years ago. I did have to do a little editing of the .conkyrc file on each. In the VM installation, I had to comment out the line for the second CPU core since there was only one core. It displayed an error about trying to access a core that didn’t exist. On the PC, I had to edit the Network section because the system saw the network interface as enp2s6 rather than eth0. The card was a Netgear FA311 Fast Ethernet card. I don’t know if the device name is a peculiarity with the card or with Peppermint.

Another thing I notice with my script in Peppermint was that the time was slightly to the left of center. In my installations with Ubuntu and Mint, it was always perfectly centered. I was able to fix the problem by changing the ${alignc 35} at the beginning of the penultimate line of the script to ${alignc}. I suspect that the 35 was some sort of an offset of some sort. Removing the 35 from the line on a Mint installation moved the time to a bit right of center. That’s something to be aware of, I guess.

I had installed conky on the VM yesterday and when I started the VM today, conky displayed as expected so adding the conky.desktop file to ~/.config/autostart/ is all that’s needed to launch it at boot-up. After installing it on the PC today, I opened the Autostart GUI and confirmed that conky was listed.

Satisfied that the installation commands were correct, I restructured the My Conky Configuration page. Under the Installation heading, I listed the steps to install conky from the command line. I put the commands in bold text. You can highlight and copy to the clipboard. To paste them in the terminal use the Crtl+Shift+v key combination. Before the actual installation steps, I include commands to check for battery, CPU, and network interface information.

I kept some of the old installation information in case anyone wants to do it that way. Be aware that menus may be different depending on the distro you’re using.

After the script itself, I created a Notes heading that includes the notes I’ve made for each update. It’s kind of a changelog, I guess.

I’ve abandoned the idea of creating a bash script for the installation. There are only three commands and it’s easy enough to copy and paste them into the terminal.

In my instructions, I used gedit but you can use whatever editor you feel comfortable with. A graphical editor such as gedit works well if you need to do much cutting and pasting like when you need to change eth0 to something else on several lines. I like to use nano from the command line for small changes.


Latest conky update

I spent several hours working on my conky script, bouncing between three machines to make sure it was displaying everything right. I think I finally have it the way I want it. I did make a new comment to conky modifications but that was before I finished for the day.

I added a line to the script to display the processor make and model information, placing it at the top of the PROCESSOR section. It uses grep, sed, and cut to get a string out of the /proc/cpuinfo file. The line will probably needed to be edited to get a string of the proper length for your processor name.  You’ll need to view the cpuinfo file to see how many characters you’ll need to adjust the ‘cat -c 1-xx’ at the end of the line. Or you can run the full command in a terminal, trying different values. You can open it in gedit and copy the command to the clipboard and paste into your terminal using Ctrl-Shift-V.

I also added a few lines to give a numerical and bar graph display of battery power remaining. In the script I have on the web page and the conkyrc.txt file, these lines are commented out. If you’re running the script on a laptop, just remove the hashtags from the appropriate lines.  I wasn’t able to find a reliable way for the script to determine if a battery existed.

I cleaned up the NETWORK section so that the LAN and WLAN displays were consistent and to generally clean things up. I’ve noticed that if my Internet connection is down, the Public IP line will just drop from the display when conky refreshes. For wireless connections my online script had lines to display SSID and Connection quality but they were missing from the actual script I was running on my laptop. I was endeavoring for consistency among my own systems as well.

As always, I updated My Conky Configuration page with the revised script along with the updated conkyrc.txt file and a new screen shot. Below are the conky displays for my laptop and my main desktop PC. This should give you some idea of how it looks.

%d bloggers like this: