Register
It is currently Fri Aug 22, 2014 5:46 am

Help with quoting needed (SOLVED)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Mon Aug 17, 2009 2:22 am   

Joined: Mon Aug 17, 2009 2:11 am
Posts: 4
I have the following command for monitoring network interface link status :
Code:
watch 'for i in `ifconfig | cut -f 1 -d " " | grep -v lo` ; do echo $i ;sudo ethtool $i | grep Link ; done'


It works fine giving me the following output:
Code:
Every 0.5s: for i in `ifconfig | cut -f 1 -d " " | ...  Mon Aug 17 11:14:53 2009

eth0
        Link detected: yes
eth1
        Link detected: yes


Now I want to open a new terminal window with this command so I need to do something like this:
Code:
gnome-terminal -e watch 'for i in `ifconfig | cut -f 1 -d " " | grep -v lo` ; do echo $i ;sudo ethtool $i | grep Link ; done'

Here I go into troubles because the argument string for the -e switch must be quoted and putting the whole string inside single or double quotes does not work because I already have quotes inside the string. Please, help.


Last edited by jackhab on Mon Aug 17, 2009 6:30 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Mon Aug 17, 2009 3:05 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
It's actually quite easy.

Code:
gnome-terminal -e "watch 'for i in `ifconfig | cut -f 1 -d \" \" | grep -v lo` ; do echo $i ;sudo ethtool $i | grep Link ; done'"


Just escape the quotation that will "escape" you from the current string.

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Mon Aug 17, 2009 6:10 am   

Joined: Mon Aug 17, 2009 2:11 am
Posts: 4
Sorry but now I have watch running and giving me:
Code:
Every 2.0s: for i in eth0                          ...  Mon Aug 17 15:08:31 2009
sh: Syntax error: word unexpected (expecting "do")


Top
 Profile  
 PostPosted: Mon Aug 17, 2009 6:26 am   

Joined: Mon Aug 17, 2009 2:11 am
Posts: 4
The working version is this:
Quote:
gnome-terminal -e 'watch for i in `ifconfig | cut -f 1 -d \" \" | grep -v lo` ; do echo $i ;sudo ethtool $i | grep Link ; done'


I.e. the whole command must be single-quoted and the for statement should not be quoted at all.

Thanks a lot, Fredrik. I thought I need to escape something to solve it but I tried to escape the space after the -d switch instead of the quotes surrounding it.

Regards.


Top
 Profile  
 PostPosted: Wed Aug 19, 2009 8:28 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 535
Code:
gnome-terminal -e "watch -d \"ls --hide=lo /sys/class/net | while read line; do ethtool $line; done\""
less commands, less troubles.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP