LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-18-2016, 12:18 AM   #1
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Rep: Reputation: Disabled
combine output with xargs


[root@karthik-linv ~]# which ethtool
/sbin/ethtool

What I'm trying to achieve is how can I run "/sbin/ethtool eth0" from a single command. This is important because I've to run this from a script. Since some of the unix machines have ethtool under "/usr/sbin/" I need to find the directory and execute it from there.

I'm trying this but it's not working as eth0 is added before to /sbin/ethtool instead of after.
[root@karthik-linv ~]# which ethtool | xargs -l eth0
xargs: eth0: No Such file or directory

Best Regards,
Karthik
 
Old 03-18-2016, 12:36 AM   #2
timl
Member
 
Registered: Jan 2009
Location: Sydney, Australia
Distribution: Fedora,CentOS
Posts: 750

Rep: Reputation: 156Reputation: 156
First of all, get out of root and login as a normal user

Maybe I am missing what the problem is here. Can't you just say

Quote:
ethtool eth0
 
Old 03-18-2016, 12:49 AM   #3
karthik4455
LQ Newbie
 
Registered: Aug 2014
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by timl View Post
First of all, get out of root and login as a normal user

Maybe I am missing what the problem is here. Can't you just say
Hi Tim,

Actually I'm including this like below in my perl script:
(ethtool eth0 | grep Duplex)

However, when I execute my script I'm seeing below:
bash: line 10: ethtool: command not found

So to resolve this I have to provide the path as well like (/sbin/ethtool eth0 | grep Duplex). When I do this it's working. Only issue I foresee here is some of the linux systems have ethtool within /usr/sbin/ethtool. This is the reason I'm trying to find the path using which command and interpret the output.
 
Old 03-18-2016, 01:36 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Why not assign the output to a variable and use as a command:
Code:
ett=$(which ethtool)

$ett eth0
 
Old 03-18-2016, 04:55 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
in perl you can easily check if /sbin/ethtool and/or /usr/bin/ethtool exists. And use that.
 
  


Reply

Tags
xargs



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
[SOLVED] xargs output with more space hoi Linux - Newbie 1 04-19-2014 07:51 AM
find . -mtime +1 | xargs ls -ltr, giving different output on same OS hamijami Linux - General 1 09-25-2013 10:42 AM
[SOLVED] Xargs with output of find thund3rstruck Programming 6 07-17-2011 08:26 AM
When I use xargs with echo, why does the output contain an extra space? web_janitor Linux - General 2 08-20-2009 04:18 PM
Can't figure out the combine and formatting of output to a file HyperTrey Programming 11 12-12-2008 01:40 PM

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

All times are GMT -5. The time now is 11:17 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