LinuxQuestions.org
Help answer threads with 0 replies.
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 05-04-2013, 07:40 AM   #1
mirzasoltan
LQ Newbie
 
Registered: Oct 2010
Posts: 28

Rep: Reputation: 0
help with running script


hi everyone,
i write a script but i have a problem with part of it, i want to run a command in my script but my script doesn't stop until that command done, for example:

if [ ! $? = 0 ]
then
mplayer /root/alarm.wav
R=10
while [ $R -gt 0 ]
do
clear
echo "there is an error..."
sleep 0.5
clear
sleep 0.5
R=$(($R-1))
done
else
echo "everythings ok."
fi

i want to until script play "alarm.wav" (alarm.wav has 60 seconds duration) next lines (echo "there is an error...") appear in screen.
in other words, i want to play the sound and showing message both in a time.

anyone help please.
 
Old 05-04-2013, 07:56 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You can put a program in the background by placing an ampersand (&) behind it:
Code:
aplay /root/alarm.wav &
I wouldn't use mplayer to play the sound (mplayer needs the terminal), use aplay instead.
 
1 members found this post helpful.
Old 05-05-2013, 04:26 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
@mirzasoltan Your descriptions are a little confusing. Can you describe step by step what you actually want to do?
 
Old 05-05-2013, 04:55 AM   #4
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Also /root is an odd place to put a .wav file
jdk
 
Old 05-05-2013, 04:50 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.


I personally would set the warning up as a function, and use a for loop instead.

Code:
warningmessage(){
    mplayer /path/to/alarm.wav &

    for (( R=10; R>=0; R--)); do
        clear
        echo "there is an error..."
        sleep 0.5
        clear
        sleep 0.5
    done
}


command_that_could_fail

if (( $? == 0 )); then
    echo "everythings ok."
else
    warningmessage
fi
The c-style for loop and the ((..)) arithmetic evaluation brackets are bash/ksh specific, however.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Issue in running commands in expect script from shell script yadvinder Programming 0 05-31-2012 05:07 AM
Shell Script to start a program either not running or kill if running avataratar Linux - Newbie 1 03-29-2012 03:45 AM
Difference between running script (.sh) from .bash_profile and running from login dsimha Linux - General 4 01-17-2012 11:06 AM
Shell Script: Getting signal handlers to work when running an application by script pkjss Programming 4 09-14-2011 05:23 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM


All times are GMT -5. The time now is 05:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration