18Jul/19

Bash convert seconds to human readable

function displaytime {
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf ‘%d days ‘ $D
(( $H > 0 )) && printf ‘%d hours ‘ $H
(( $M > 0 )) && printf ‘%d minutes ‘ $M
(( $S > 0 )) && { (( $D > 0 || $H > 0 || $M > 0 )) && printf ‘and ‘
printf ‘%d seconds\n’ $S; } || printf ‘\n’
}

-bash-4.1$ displaytime 604800
7 days
-bash-4.1$ displaytime 604801
7 days and 1 seconds
-bash-4.1$ displaytime 800
13 minutes and 20 seconds
-bash-4.1$ displaytime 780
13 minutes

28Apr/19

Wrong Port Connected Check With ifconfig

We need to run ifconfig and look for the status line.

Remember this about ifconfig output:

* if “status: active“, the port is linked up and sending traffic (now you just need to make sure it has an IP for it to be able to communicate on a network). You can see it is sending traffic with tcpdump -i <port>
(hit Control-C after a few seconds; even ports that are linked up w/ a missing IP should still be sending out and receiving some L2 switch traffic: STP, ARP, LLDP)

* if “status: no carrier“, the port is not linked up and therefore not sending traffic . If you run tcpdump on this port, you will see 0 packets.

* if “status:” line is missing, then the port is disabled. Enable it w/ “ifconfig <port> up” to see if it has a link (you can optionally disable the port afterwards if you see it has no carrier using “ifconfig <port> down“)

18Apr/19

Grepping Thru All Rotated Logs

If your system gzips and rotates your logs.

You can use this trick to search thru all of them.

# zgrep -i — “SEARCHTERM” $(ls -1Str /var/log/messages*)

Another way

# zgrep -i — . $(ls -1Str /var/log/messages*) | grep “SEARCHTERM”

Sidenote: if you get an error try to replace “zgrep” with “zegrep”

03Apr/19

A good free syslog server

Personally, I just tried “Syslog Watcher” version 5.0.4 and it does a good job. I can start it by hitting “Start Server” then configured syslog clients to point at it. You can click on a message, then it will show up in the message view with every detail. Additionally you can hold Control and Mouse Wheel Down or Up to zoom in or out (just like in Notepad++)

Of course everyone is aware of Kiwi Syslog Server. I find Syslog Watcher more interesting, but that is just me.

27Apr/18

Find UPNP devices on your network – ex: ReadyDLNA or UPnP routers

Got info from here: https://stackoverflow.com/questions/18363833/how-can-i-list-upnp-server-renderer-in-command-line-console-mode-on-linux

Get the Upnp test tools

Example 1:

Find all Upnp devices (note their target names start with urn:…. It will hint at what service it is, ex: Layer3Forwarder, MediaServer, etc..)

Example 2:

Find DLNA servers which are served via Upnp (which has a target of MediaServer, urn:schemas-upnp-org:device:MediaServer:1)

The end

24Jan/18

bash simple variable substitution

You can use bash to do simple substitutions of variables, just like you can with sed. The bash trick turns out to take up less characters (bytes).

Lets set some variable

To replay it back:

or

Output of both:

 

Format

To do a simple substitution of the value/contents of a variable structure it like so. Put in the from part the thing you want to change (it can be a char or some chars), then it will replace them with the part you put in to (which can be a char or several chars). Note if mentioning special chars to escape them (example \ needs to be \\). Spaces are not considered special chars in this case.

echo ${VAR//from/to}

Then all of the parts that are from will change to to when the variable VAR is called.

Example 1

Lets replace all s with a S. You have to use the second notation type and add some parameters

Output:

  • Note: sed can be used to do the same substitutions

or

 

Example 2

Let replace all is with IZ

Output:

  • Note: sed can be used to do the same substitutions

or

 

Example 3 – filenames with spaces

What about converting an absolute path which has spaces to something with escaped spaces (backslash followed by space)

Output:

We convert spaces ” ” to “\ ” however in bash to print a backslash “\” we need to put an extra one “\\”

Output:

  • Note: sed can be used to do the same substitutions

or

The end.

15Nov/17

Bash scripting dealing with any characters in strings or filenames

Imagine a file list, list.txt, like this one

Naturally you could deal with it like so

Or just use the $i variable as its already the file and do a one liner like this:

cat list.txt | while read i; do dosomething "$i"; done This will dosomething against image1.jpg, image2.jpg and image3.jpg.

Easy simple loop.
Now imagine a file list with special characters like this one, listB.txt:

The same loops will not work and will error out. So you have to treat them like so:

Note: do not put quotes around the eval.

This will then properly process the files as it will naturally escape them.
It will properly run dosomething against those 5 files.

How does it do that? You can print out the FILE variable to understand. It simply backslashes (escapes) all of the special characters.

Output:

Sidenote: from talking with others, nohup dosomething &> whatever &  can be weird if dosomething has to operate on file with special characters. Instead its better to put it in the background and then just disown it, like so:

 

The end.

26May/17

My Favorite X-Plane 10 / 11 Controls – Rudder, Joystick & Throttle Setup

I do not take credit for this controller layout. I really like it and would like to have a copy easily available so I hosted it here, also I would like to share with you all my favorite controllers. These have been designed by Catstrator, all credit goes to him (if you see this, I hope its okay that I am using this). Full credit goes to you good sir!

Xplane Controls (credit goes to catstrator) – click on picture to enlarge

Joystick & Throttle: Saitek Pro Flight X-55 Rhino H.O.T.A.S. (Hands on Throttle and Stick) System for PC

Rudder: Saitek Pro Flight Rudder USB Pedals (these are different than the picture, however they both support Yaw & Left & Right Toe Break)

Setup Video for X-Plane 11 (there is also one for X-Plane 10 on his channel): https://www.youtube.com/watch?v=hFn-zztS5ho