Ok, awesome, I got it to work.
(disconnected was spelled wrong and there wasn't some needed spaces in the code, but it work fine now)
Now to get it to play a file of my choice.
#!/bin/bash
IFACE="ttyUSB0"
SLEEP_TIME="1s"
while true; do
[ "$(nmcli dev status | grep $IFACE | awk '{print $3'})" == "disconnected" ] && vlc '/home/grant/Desktop/warningredalert.mp3' || echo "STILL CONNECTED"
sleep $SLEEP_TIME
done
Seems to work great, now to clean up the code a bit (using your example)
#!/bin/bash
IFACE="ttyUSB0"
SLEEP_TIME="1s"
SOUND_FILE='/home/grant/Desktop/warningredalert.mp3'
while true; do
[ "$(nmcli dev status | grep $IFACE | awk '{print $3'})" == "disconnected" ] && vlc $SOUND_FILE || echo "STILL CONNECTED"
sleep $SLEEP_TIME
done
And it works great. Since I use VLC for just about everything, it would be nice if I had a different player to run it in loop.
So since I have gnome mediaplayer already instaled. I replace vlc with gnome-mplayer and set it to loop (settings menu)
The player just keep the settings so when it's done, it loops again.
Thanks a million guys!
--- In LINUX_Newbies@yahoogroups.com, J <dreadpiratejeff@...> wrote:
>
> On Tue, Oct 11, 2011 at 11:32, grantrocket2 <mars_rover@...> wrote:
> > Wow I didn't expect a response so fast.
>
> You caught me at a quite moment between meetings and actual work :)
>
> > So I tried it (copy and paste into terminal)
> > nothing
> > Then I tried sticking it in a text file (rightclick, new file, empty text file)
> > and running the file as sudo.
> > Nothing. Here's what I'm using.
>
> Removing MY quote markers to highlight something
>
> while true; do
> > [ `nmcli dev status |ttyUSB0|awk '{print $3'}` == "disconnected" ] && echo
> "LOST CONNECTION!" || echo "STILL CONNECTED"
> > sleep 60s
> > done
>
> You need to lose the '>' ... sorry, that's an artifact of doing
> multi-line commands in a bash shell... I didn't think to strip those
> out. Also, the comparison says simply 'ttyUSB0', not 'grep ttyUSB0'.
> Without the grep, the shell will interpret ttyUSB0 as a command name
> and error out.
>
> Here it is all in one line:
>
> while true; do [ "$(`nmcli dev status | grep ttyUSB0|awk '{print
> $3'}`)" == "disconnected" ] && echo "LOST CONNECTION" || echo "STILL
> CONNECTED"; sleep 1s; done
>
> (note that I changed the sleep time from 60s to 1s for expediency and
> I've cleaned the code up a little)
>
> and here it is on my system:
>
> bladernr@klaatu:~$ while true; do [ "$(`nmcli dev status | grep
> ttyUSB0|awk '{print $3'}`)" == "disconnected" ] && echo "LOST
> CONNECTION" || echo "STILL CONNECTED"; sleep 1s; done
> STILL CONNECTED
> STILL CONNECTED
> STILL CONNECTED
>
> Note that it's saying STILL CONNECTED because it's not finding a
> ttyUSB0 on my machine, thus the AND comparison fails, so it drops to
> the OR part of the statement. The '!' that was in "LOST CONNECTION!"
> was giving my terminal fits, so I just removed it. Ultimately, that's
> all replaced with something that plays a sound anyway, right?
>
> And note the ';' between the statements... that lets you put multiple
> commands on a single line in the terminal (single separate commands,
> which is different from piping the output of one command into another
> using '|'.
>
> > I like that your script doesen't use ping to test connection.
>
> No need to if you're just testing that the connection is up. Testing
> that it's valid is an entirely different story. There are plenty of
> cases where you could have an active connection but no actual
> connectivity. In fact, I just had that happen... my router dropped
> it's WAN connection, but still had it's LAN running, so I could ping
> the router, but nothing beyond that.
>
> > So, um how do I put it into a clickable script?
>
> put this into a file:
>
> #!/bin/bash
>
> IFACE="eth0"
> SLEEP_TIME="1s"
>
> while true; do
> [ "$(nmcli dev status | grep $IFACE|awk '{print $3'})" ==
> "disconnected" ] && echo "LOST CONNECTION" || echo "STILL CONNECTED"
> sleep $SLEEP_TIME
> done
>
> Change the permissions on the file to be executable:
>
> chmod +x /PATH/TO/FILENAME
>
> and I don't use mint, but if it's anything like standard Ubuntu, you
> should be able to:
>
> Right click on desktop
> Click Create Launcher...
> Select Application in Terminal for Type
> Enter a name for the launcher
> Click Browse, locate the script and select that.
>
> That should create a launcher on your desktop that you can click to
> run that opens a terminal and starts the script. At least it works
> fine on my system...
>
> Also note that I created two variables at the top of the script...
> there you can set the time and interface to check without changing the
> actual code below them.
>
> Also, this still doesnt play any sound... but it's enough to get you started..
>
Tuesday, October 11, 2011
[LINUX_Newbies] Re: Audible internet disconect sound?
__._,_.___
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.
MARKETPLACE
.
__,_._,___
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment