Samstag, 30. Mai 2015

One for between

The is a simple example how to read directly from a list file and check if that variable exists as directory.
If that is true, if writes to the tasklist, if not, it writes to another list.

Since one can pass multiple arguments to touch, one can even use parameter expansion to create multiple files at once.

#!/bin/bash
DATA="$HOME/data"
LIST="$DATA/mylist.txt"
JOB_NO="$DATA/job_no.txt"
JOB_YES="$DATA/job_yes.txt"

[ -d "$DATA" ] || mkdir -p "$DATA"
touch $JOB_{NO,YES} $LIST

while read dirfolder
do    [ -d "$dirfolder" ] && \
    echo "$dirfolder" >> "$JOB_YES" || \
    echo "$dirfolder" >> "$JOB_NO"
done<"$LIST"

Have fun

Building libdvdcss

My favorite linux distribution Fedora has a release cycle of roughly 6 months, and i tend to twink often too much with that running system i actualy would have had attainted...

It just so happens that i quite often (re-) install the OS even if its just to try the fresh built LiveOS.
Anyway, figured named LiveOS could not succeed because one of the rpm repositries was ready with that just yet.

How nice, for that i figured, that download and comile libdvdcss is easier than to run after the latest package specificly for my OS.

One has to be aware however, that my system is a developer oriented machine, so most of the required applications were already installed.
A good point to start would be:

On Fedora for example:
sudo dnf install make autoconf automake gcc
Then simply save the below code as a script, and execute it after a fresh installation.
git clone git://git.videolan.org/libdvdcss
cd libdvdcss
autoreconf -i
./configure --prefix=/usr
make && sudo make install

Hope this helps

Freitag, 29. Mai 2015

TUI update 0.8.1-4

  • Changed:   tui-new-*, had some invalid references left
  • Changed:   tui-new-*, added some default values to settings.conf, like which templatefile to use if no arguments are passed
  • Changed:   tui-filemgr, got forgotten when changed to list files
Get it at https://github.com/sri-arjuna/tui/releases/tag/v0.8.1-4
Or update it like:
su
cd /path/to/tui-git-repositry
git pull
echo y n | ./install.sh
 

Mittwoch, 27. Mai 2015

TUI v0.8.1-3 (stable hotfix)

Taming the beast was a hard feast, it was a wild one with wit.
The horse is back to the stable, and baby i smile like Clark Gable.

https://github.com/sri-arjuna/tui/releases/tag/v0.8.1-3

It should be back to were it was before the RC file.

Dienstag, 26. Mai 2015

Background jobs, exit status

Figured another way to get an exit status of a job ran in background.

Obviously, these examples are simplified.
Each first of the two, is the 'one-liner' and the 2nd code box shows the structure with idention.

1) In this first one, we're sending the output of the background job into a variable, which we echo at the end.
This works, but doesnt really take advantage of a 'background' job.
ret=$(( sleep 2 ; [ -d not-existing ] ; echo $?) &)
echo $ret
ret=$(
    (
        sleep 2
        [ -d not-existing ]
        echo $?
    )&
)
echo $ret


2) This one applies alot more to what one usualy expects as a background job. (AFAIU) mkfifo lets the read-command wait until something is written to its passed file.

tmp=~/.cache/$$~ ; mkfifo "$tmp"
( sleep 10 ; [ -d not-existing ] ; echo $? > "$tmp") &
read RET < "$tmp" ; [ "$RET" = "0" ] && echo "GOOD!" || echo "BAD"
rm -f "$tmp"
tmp=~/.cache/$$~
mkfifo "$tmp"
(
    sleep 10
    [ -d not-existing ]
    echo $? > "$tmp"
) &
read RET < "$tmp"
[ "$RET" = "0" ] && echo "GOOD!" || echo "BAD"
rm -f "$tmp"
3) And to close the top 3, my most used code of these three.
This one loops while the background job is active and prints dots while its running. One could replace the printed string to update the text accordingly.

tmp="~/.cache/$~"
( sleep 5 ; [ -d not-existing ] ; echo $? > "$tmp") &
pid=$!
while ps $pid 1>/dev/zero;do sleep 0.5 ; printf ".";done
cat "$tmp"
tmp="~/.cache/$~"
(
    sleep 5
    [ -d not-existing ]
    echo $? > "$tmp"
) &
pid=$!
while ps $pid 1>/dev/zero
do
    sleep 0.5
    printf "."
done
cat "$tmp"

Last but not least, i'll have a tool to help with such a task.
Its called: tui-psm, which names Text User Interface - Paralell Script Manager.
You can pass as many scripts as an array can hold, and limit the paralell executed scripts to any number you want (5 is default).
tui-psm script1.sh script2.bash script3.csh

But it can more, for example, if you need at least 3 scripts to be executed successfully before you attempt to run script 5, this could be your approach:
tui-psm -cq script1.sh script2.bash script3.csh ./script4.zsh
[ $? -ge 3 ] && ./script5.ash

Hope this helped.
Have fun scripting!

Montag, 25. Mai 2015

Taming the beast, TUI back to stable

Now after the big excitement of the successfull changes to use an invidiual rc file for all its used variables, basic usage seems to be back to normal again.

It is causing a rush to figure one successfully installs the bash completition, accidently to a wrong and non-working path.

But this massive change also helped me to figure out which internal variables to share and which not, so i've added the function 'provides' to figure that out.

tui provides
Will print a hughe and long list with all the variables used internaly and which you may use as well.

If you
source  tui
you'll have all of those variables available, but sourcing just the rc file, and the wanted file providing the variables you want can increase usage speed.
source ~/.tui_rc || . tui
source $TUI_FILE_{APPS,SETTINGS}

Also several small hotfixes, of which i was sure i have had applied already 6 months ago....

Hope you like it, enjoy! :)

Freitag, 22. Mai 2015

TUI 0.8.0-2, The RC File release

Get it here:
https://github.com/sri-arjuna/tui/releases/tag/v0.8.0-2

Read about it here:
http://www.unix.com/shell-programming-and-scripting/253496-tui-text-user-interface-framework-scripts.html

Also the installation script has changed:


Hope you like the changes.
Enjoy! :)

Dienstag, 19. Mai 2015

Simply check a single ip or a range of ips within your LAN

IP_PRE=192.168.1
[ -z "$1" ] && echo "Usage: ${0##*/} 15 30-37 42 .."

for num in "${@}";do
# Parse all the arguments
    if [ "-" = "$(echo $num|tr -d [[:digit:]])" ]
    then    # Its a range, as it contains a '-'
        range_start=${num/-*}
        range_end=${num/*-}
        range=${seq $range_start 1 $range_end}
    else    # It has no range, its a single number
        range=$num
    fi
    # Parse all the numbers filled in range
    for r in $range;do
        ping -c1 $IP_PRE.$r 2>/dev/zero 1>/dev/zero && \
            echo "$IP_PRE.$r is up" || \
            echo "$IP_PRE.$r is down"
    done
done

Samstag, 16. Mai 2015

Todays achievement

I'm trying to provide some information on the variables used by TUI, reading them from 'memory' as env doesnt list them anymore (since heartbleed, still accessable by "echo ...").

Anyway, so me kind of proud this worked on first attempt :)
List all the variables starting with TUI_ and RET_:
echo ${!TUI_*} ${!RET_*}
While this is already nice, as it prints all variable names starting with either TUI_ or RET_, i'd like to show the values of these variables as well, so the user gets an idea what to expect.
Thought, eval might be usefull at this point, to show the current set paths, files, colors and default return values.

for foundVar in ${!TUI_*} ${!RET_*}
do    tui-printf -E \
           "$foundVar" \
           "$(tmp=\$$foundVar ; printf '%s' $(eval echo $tmp))"
done

Which then finaly printed (shortened):
:: TUI_DIR_CACHE                     /home/sea/.cache ::
:: TUI_DIR_CONF                              /etc/tui ::
:: TUI_DIR_DOCS                    /usr/share/doc/tui ::
:: TUI_DIR_INSTALL_ROOT                               ::
:: TUI_DIR_SYSTEM                      /usr/share/tui ::
:: TUI_DIR_THEMES               /usr/share/tui/themes ::
:: TUI_DIR_USER                 /home/sea/.config/tui ::
:: TUI_DIR_USER_LOGS       /home/sea/.config/tui/logs ::
:: TUI_DIR_USER_MANPAGES    /home/sea/.local/man/man1 ::
:: TUI_DIR_USER_SCRIPTS          /home/sea/.local/bin ::

Mittwoch, 6. Mai 2015

Get the extension of a filename

Every now and then, one needs to decide upon a file its extension what to do.

This is what i've added as tui-str-extension:
out=""
FN=$( echo "$1" | sed s," ","",g)    # Remove any spaces and make it a single string
for chance in $(echo "$FN"|sed s,"\."," ",g)    # Use dots as string seperators
do    out="$chance"
done
if [ "$out" = "$FN" ]
then    echo ""
else     echo "${out%\ /}"     # Remove any tailing or single space
fi
Hope you like it :)