Friday, November 10, 2017

List directories via 'ls -d' - surprised me

List directories via 'ls -d' - surprised me

This was one of those feelings where I was left surprised with the humble linux command 'ls'

Here is what the man page says about ls -d -

-d, --directory

list directories themselves, not their contents
tried many times 'ls -d' all I got back was -
[sanjayu@dhcp-0-69:~]$
ls -dl
drwx--x---+ 110 sanjayu sanjayu 12288 Nov 10 19:39 .
[sanjayu@dhcp-0-69:~]$
ls -d
.
Now definitely there is something wrong, and I started searching the google. frankly not much came out as a help. I know we can do this via find ie find ./ -type d (using -maxdepth one can control recursive-ness). However, what intrigued me was man page and the contrary behaviour.

Finally found this - http://www.rapidtables.com/code/linux/ls.htm

ls -d */

Monday, March 6, 2017

Yum: search for a package through the disabled repos

Recently, I was searching for a package, it soon turned out that I need to archive this at least for myself. Here is it

Look for all the repos :

[stack@undercloud ~]$ yum repolist all
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: mirror.raystedman.net
* extras: mirror.pac-12.org
* updates: mirrors.sonic.net
515 packages excluded due to repository priority protections
repo id repo name status
!base/7/x86_64 CentOS-7 - Base 9,363
!centos-ceph-jewel/7/x86_64 CentOS-7 - Ceph Jewel 82
!delorean delorean-python-networking-bigswitch-2dd6c2693b8b203b9ac2148e9747609161514af9 520+236
!delorean-newton-testing/x86_64 dlrn-newton-testing 830+515
!extras/7/x86_64 CentOS-7 - Extras 264
!rdo-qemu-ev/x86_64 RDO CentOS-7 - QEMU EV 70
!updates/7/x86_64 CentOS-7 - Updates 856
repolist: 11,985

Find a package in disabled repolist

#!/bin/bashset -ex

for i in `yum repolist all | awk '{print $1}' | cut -d '/' -f 1 | sed 's/!//'`;
do
yum --disablerepo="*" --enablerepo="${i}" search $1done

Breaking up the script


  1. yum repolist all | awk '{print $1}' --> get the first columns and remove anything after '/'
  2. sed 's/!//' remove the annoying ! at the beginning
  3. search for the package use -
 yum --disablerepo="*" --enablerepo=$REPONAME search $PACKAGE_NAME


More here

Wednesday, March 1, 2017

Uploading to gist and sharing

Gist is a cool tool, here we are going to see how to use it from cli and use it as archiving or sharing utility.


Steps - 

[gist]
token: 
editor: 
  • Now you are set, use the following - 
gist create  - creates a new gist
gist edit    - edit the files in your gist
gist list    - prints a list of your gists
gist clone   - clones a gist
gist delete  - deletes a gist from github
gist files   - prints a list of the files in a gist
gist archive - downloads a gist and creates a tarball
gist content - prints the content of the gist to stdout
gist info    - prints detailed information about a gist
gist version - prints the current version

Tuesday, February 28, 2017

Skydive (real-time network topology and protocols analyzer) on Fedora

Skydive Installation on Fedora 25

Dependencies

  • Go >= 1.5
  • Elasticsearch >= 2.0
  • libpcap
  • libxml2
  • protoc >= 3.0

On Fedora, Install steps are -

  • Install GO
    • wget -c https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
    • tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
    • add the following in /etc/profile or ~/.profile
      export PATH=$PATH:/usr/local/go/bin
  • Install Elasticsearch
    • Elasticsearch requires JDK, hence we will install openjdk, as it works with it
      • sudo dnf install java-1.8.0-openjdk icedtea-web
    • Download RPM from https://www.elastic.co/downloads/elasticsearch
    • Install and start the services - 
    • sudo systemctl enable elasticsearch.service
      sudo systemctl start elasticsearch.service
  • Install libpcap, libxml2
    • dnf install gcc gcc-c++ glibc unzip libpcap libpcap-devel libxml2 libxml2-devel
  • Install protoc (via building from source)
    • wget -c https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip
    • unzip protoc-3.2.0-linux-x86_64.zip
    • cd protoc-3.2.0
    • ./configure 
    • make install
  • Build skydive
    • export GOPATH=`pwd1`
    • mkdir -p $GOPATH/src/github.com/skydive-project
    • git clone https://github.com/skydive-project/skydive.git $GOPATH/src/github.com/skydive-project/skydive
    • cd $GOPATH/src/github.com/skydive-project/skydive
    • make install

Running Skydive

  • Now that skydive installed, check via running - skydive allinone. If this works, we are ok, we can configure skydive to run with our tripleo setup
  • Create skydive.yml with the following content -
https://gist.github.com/adc0ded6c4d648cb9d1b531d51b90c1f
  • start the analyzer via - skydive agent --conf /etc/skydive.yml
  • start the agent  - skydive agent --conf /etc/skydive.yml
  • Fire up browser and watch the url http://hostname:8082/

Running some test scenarios

  • Download https://github.com/skydive-project/skydive/blob/master/scripts/simple.sh
  • run it, sudo bin/simple.sh start 172.16.99.1/24 172.16.100.1/24 to create two VM over a bridge br-int. Look at the flows in UI, enjoy!

Final Results

UI screenshot -

List directories via 'ls -d' - surprised me

List directories via 'ls -d' - surprised me This was one of those feelings where I was left surprised with the humble linux comm...