.

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
simargl

.

#1 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 16:04, edited 3 times in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#2 Post by Karl Godt »

probably try to use grep -m1 or grep | tail -n1 so if more than one line in /tmp/output it piks the first or the last , so if tail at the very end might be already get one single line after all the sed edits .

cat /tmp/output | grep is seen everywhere, but grep /tmp/output should do it also .

simargl

#3 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 15:09, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

while [ "$(pidof yad)" ]; do
Sometimes seems not to work as it could.
Probably missing a break, since the test for "$(pidof yad)" might only run once at while begin.
Probably needs additionally a
[ "$(pidof yad)" ] || break
inside it to stop the current loop. Otherwise you'll probably have multiple instances of the while loop running .
like

Code: Select all

while [ "$(pidof yad)" ]; do
  sleep 5s
  [ -f /tmp/output ] || break
  [ "$(pidof yad)" ] || break
  NEW_TITLE=$(grep 'StreamTitle' /tmp/output | tail -n1 | sed 's|ICY Info: StreamTitle=||g' | sed 's/;[^-]*$//' | sed s/"'"/" "/g)
  if [[ "$NEW_TITLE" != "$TITLE" ]]; then
    notify-send -i simple-radio "$action" "$NEW_TITLE"
    TITLE="$NEW_TITLE"
  fi
done

simargl

#5 Post by simargl »

.
Last edited by simargl on Sun 01 Sep 2013, 15:09, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#6 Post by Karl Godt »

No GUI freak here, and know nothing about yad.

You have yad GUI and yad --notification .

Probably this is confusing things , so running a new instance of the yad gui would prevent the loop from exiting/breaking.

Otherwise yad --notification might need killall -9 which almost every time succeeds .

You should remove the >/dev/null s to have a better view on things .

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

Re: lost inside while loop

#7 Post by PANZERKOPF »

simargl wrote: like variable $action
IIRC:
Loop runs as a separate process so all variables inside it are not visible by parent process.
SUUM CUIQUE.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

Please don't poll for file changes.

Code: Select all

touch /tmp/file #make sure it exists
inotifyd - /tmp/file:c |while read DUMMY; do
    echo actions to do when file is changed
done &
inotifyd will be dormant (using almost no resources) until awakened by an inotify event from the kernel (no polling) - you can get 500 events in 1 second or have the process running dormant for days and it would pop right up as soon as the file changes
Note: inotifyd can monitor stuff other than just changes (:c) including entire directories
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

simargl

#9 Post by simargl »

.

Post Reply