command :
lsmod
loaded kernel module list
command :
modinfo `lsmod | awk {'print $1'}` | awk {'print $2'}
loaded kernel module file position
I want list
KernelModule | file position
ex :
xfs | /lib/modules/3.10.0-514.el7.x86_64/kernel/fs/xfs/xfs.ko
how to get example list Command?
Try this:
lsmod | grep -v ^Module | awk '{print $1}' | xargs -n 1 -I MOD sh -c "echo -n MOD; echo -n ' | '; modinfo MOD | grep filename | awk '{print \$2}'"
Related
I have a command to grep a file with fullpath that contain a "TypeId: 0", here is the command
grep -rnw /home/username/app/data/store/0/part/.mv -e "TypeId: 0" | awk -F ":" '{print $1}'
and here is the result:
/home/username/app/data/store/0/part/.mv/521/1673332792072/segmentconfig.yaml /home/username/app/data/store/0/part/.mv/521/1673333077920/segmentconfig.yaml /home/username/app/data/store/0/part/.mv/521/1673333077920/segmentconfig.yaml.old /home/username/app/data/store/0/part/.mv/515/1672993850766/segmentconfig.yaml /home/username/app/data/store/0/part/.mv/515/1672993850766/segmentconfig.yaml.old /home/username/app/data/store/0/part/.mv/703/1672987004847/segmentconfig.yaml /home/username/app/data/store/0/part/.mv/703/1672987004847/segmentconfig.yaml.old
Now I confuse how to grep "numofvertice" from each file from that list.
Anyone have an idea to solve this?
You could try this:
grep -rnw /home/username/app/data/store/0/part/.mv -e "TypeId: 0" | awk -F ":" '{print $1}'|xargs -I{} grep "numofvertice" {}
Like this (GNU grep):
<STDIN> | grep -oP '\b\S+\.yaml' | xargs cat
Or with ack:
cd /home/username/app/data/store/0/part/.mv
ack -wl -e "TypeId: 0" | xargs cat
From ack --help:
-l, --files-with-matches
Only print filenames containing matches
I have a task which asks to write a script which displays all partitions formatted with a specific file system, given as parameter.
I have written the script but when i run it it displays '0'. What am i doing wrong?
This is my code:
#!/bin/bash
n=sudo parted -l | tail -n +8 | awk '{print $5}' | wc | awk '{print $2}'
m=sudo parted -l | tail -n +8 | awk '{print $5}'
q=sudo parted -l | tail -n +8
for i in $n; do
if [ "[ $m | sed -n ip ]" = "$1" ]; then
echo "$q | sed -n ip"
fi
done
Different approach from yours, but does it do what you need?
lsblk -f | awk '$0 ~ fs {print $NF}' fs=ext2
I'm having errors when sending this to expect
send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print $2}'`\r"
Error:
can't read "2": no such variable
while executing
"send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print $2}'`\r""
If all you want is the PID for some process, you don't need all this messy thing: ps aux | grep someagent| grep -v grep | awk '{print $2}'.
You can get a process PID just with pgrep:
In your case it would be:
send "someagent_id=$(pgrep SOMEAGENT)\r"
try this :
someagent_id=$(ps aux | grep someagent| grep -v grep | awk '{print $2}'\r)
send $someagent_id
`` --> previous version
$ --> new version. Both do the same thing
try this
send "someagent_id=`ps aux | grep someagent| grep -v grep | awk '{print \$2}'`\r"
and maybe better with this 1 pipe only version
send "someagent_id=`ps aux | awk '/someagent/ && ! /awk/ {print \$2}'`\r"
With ps options
ps -C someagent -o pid=
send "someagent_id=$(ps -C someagent -o pid=)"
I have a tomcat server I am trying to get a list of info on for a project. I need to get the results from /etc/default/tomcat file. However some of my servers are tomcat6 and some are tomcat7 so hardcoding the filename is not going to work.
How would I dynamically insert the filename in this batch script.
#!/bin/bash
echo Server Name: `hostname`
echo CPU: `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`
FREE_DATA=`free -m | grep Mem`
CURRENT=`echo $FREE_DATA | cut -f3 -d' '`
TOTAL=`echo $FREE_DATA | cut -f2 -d' '`
echo Internal IP : `ifconfig eth0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
echo OS Memory: `cat /proc/meminfo | grep MemTotal | awk '{ print $2 }'`
echo Operating System: `uname -mrs`
***echo Tomcat Memory: `cat /etc/default/tomcat6 | grep Xmx | awk '{ print $5}'`***
Your last command can be simplified to single awk like this:
awk '/Xmx/{print "Tomcat Memory:", $5}' "$tomcatFile"
Pass "$tomcatFile" whatever tomcat filename from ver6 or ver7.
You can get output from both tomcat files in same command using:
awk '/Xmx/{print "Tomcat Memory:", $5}' /etc/default/tomcat[67]
I have this command
grep 'Some pattern' location/*filename* | cut -d ' ' -f2 | cut -d '}' -f2 |
grep -v '^$' | head -1
The above command is giving me output as some file name, such as:
abc.txt
Now I want to grep another line from this file abc.txt with matching some specific pattern, so I did this
grep 'some pattern' location/*filename* | grep -iv .tar | grep -v backup |
grep -v bkp | cut -d ' ' -f2 | cut -d '}' -f2 | head -1 | xargs grep 'some pattern'
It's not working because the abc.txt file is not present in my current directory.
Can anybody tell me how to append location path to abc.txt before passing it to xargs grep command?
You can try this,
grep 'some pattern' location/*filename* | grep -iv .tar | grep -v backup |
grep -v bkp | cut -d ' ' -f2 | cut -d '}' -f2 | head -1 | xargs |
sed 's#.*#/path/to/dir/&#g' | xargs grep 'some pattern'
If cmd produces output "bar", but you want "foobar", you can simply do:
printf foo; cmd
In your case, if you want to prepend /p/a/t/h to your output, just do:
{ printf /p/a/t/h/; grep 'some pattern' filename | ... | head -1; } | xargs ...
But you're probably better off just replacing the head -1 with sed -e 1s#^#/p/a/t/h/# -e 1q
Superficially, if the first command sequence gives you the name of a file in some directory, you need to use find to get the path name to the file:
find . -type f -name $(grep 'Some pattern' location/*filename* | cut -d ' ' -f2 |
cut -d '}' -f2 | grep -v '^$' | head -1) \
-exec grep 'some pattern' {} +
You don't need a backslash after the first line (though it would do no harm); you do need the backslash after the second line. You might specify a different starting point than . for the search.
Hi everybody Thanks for your suggestion.. any how I also found some solution for my problem..
FYI
here is what I used..
echo "dev/temp/text/"$(grep 'Some pattern' location/*filename* | cut -d ' ' -f2 | cut -d '}' -f2 | grep -v '^$' | head -1) | xarg grep 'some pattern'
A couple of ideas:
... | head -1 | sed 's,^,location/,' | xargs grep 'some pattern'
or
... | head -1 | xargs -I FILE grep 'some pattern' location/FILE