To paste into a terminal use Shift-Ctrl+V Roy
Using Kubuntu 11.10, 64-bit Location: Canada On 11 October 2011 12:50, J <[email protected]> wrote: > ** > > > On Tue, Oct 11, 2011 at 11:32, grantrocket2 <[email protected]> > 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.. > > [Non-text portions of this message have been removed] ------------------------------------ To unsubscribe from this list, please email [email protected] & you will be removed.Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/LINUX_Newbies/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/LINUX_Newbies/join (Yahoo! ID required) <*> To change settings via email: [email protected] [email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
