LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-09-2013, 04:52 PM   #1
stripe
LQ Newbie
 
Registered: Nov 2011
Posts: 22

Rep: Reputation: Disabled
bash problem


hi all
anyone know the best place to post a bash scripting question on this forum?

cheers

stripe
 
Old 06-09-2013, 04:59 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Programming ? maybe

But what is this question ?
 
Old 06-09-2013, 05:07 PM   #3
stripe
LQ Newbie
 
Registered: Nov 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
I am trying to use an error statement from the output of a terminal generated by a program (vlc) in an if statement to trigger an exit trap to cleanly exit the bash script.

the error message i want to use is added below the script.
cheers

http://pastebin.com/zpdw7Ycz
 
Old 06-09-2013, 06:28 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
you could test the exit code of cvlc like this

Code:
cvlc "$@"
if [ "$?" != "0" ];
then
    exit
fi
The above if is not very smart
Code:
cvlc "$@";cvlc_exit=$?
if [ "$cvlc_exit" != "0" ];
then
    echo "cvlc \"$@\" failed with exitcode $cvlc_exit"
    exit
fi
Better, but a case statement would give you more control ( assuming you have a list of exit codes from the source/docs )
 
Old 06-09-2013, 06:41 PM   #5
stripe
LQ Newbie
 
Registered: Nov 2011
Posts: 22

Original Poster
Rep: Reputation: Disabled
thanks for good the answers but the problem is cvlc/vlc is not exiting if the player window is closed manualy before it is finiheg it still runs in the background and the only output from the terminal when the window is closedare tgeese two lines:

***[0xad4046f0] xcb_window window error: X server failure
xdg-screensaver: Window 0x03400000 does not exist***

and i cant find a way to use that code to trigger an exit trap

hope this makes sense as ist only my second script

thanks again
 
Old 06-09-2013, 08:28 PM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Ahh, yes I miss-understood


OK , I really don't like this .. but one way to do it

Code:
coproc cvlc "$@" 2> cvlc.log
while [ $COPROC_PID ];do
    grep -q "xcb_window window error" cvlc.log && kill $COPROC_PID ; sleep 10 || sleep 10
done
you will want to put the log somewhere 'clean' instead of the working dir as above put you get the idea

I never liked vlc so I never use it
Any reason you can't use mplayer?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 05:52 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 10:53 AM
Reading a bash variable in bash scripting problem freeindy Programming 3 11-27-2008 02:29 AM
Problem with BASH Pheidon Linux From Scratch 5 06-24-2005 02:34 AM
bash problem Vincent Slackware 2 10-30-2003 05:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration