Connect to a Linux Samba Share from your Mac

Writing by on Friday, 13 of March , 2015 at 7:48 pm

Pretty straightforward. If you don’t have a samba share here’s How to Create a Network Share Via Samba Via CLI (Command-line interface/Linux Terminal). So now you have a Samba Share on Linux.

Here’s a snippet of my /etc/samba/smb.conf that contains the Linux folder on my VM that I would like to access from the Mac. (In your Mac: it will show up under /Volumes/vm_codebase).
Of course you can ssh into your Linux env, but this is more like mounting onto your Mac.

[vm_codebase]
path = /home/shivdev/codebase
available = yes
valid users = shivdev
read only = no
browseable = yes
public = yes
writable = yes

From your Mac. Open Finder : Go –> Connect to Server… –> smb://vm –> Chose vm_codebase

Now you will see it under /Volumes/vm_codebase and is accessible like a regular folder.

Leave a comment

Category: Linux,Mac

sed: 1: “/etc/hosts”: extra characters at the end of h command

Writing by on Wednesday, 11 of March , 2015 at 4:11 am

I was trying a simple sed -i on my Mac and was running into

# Does NOT work on Mac
$ sed -i ‘s/^192.168.*vm/192.168.1.12 vm/’ /etc/hosts
sed: 1: “/etc/hosts”: extra characters at the end of h command

A quick google search resulted in stackoverflow getting sed error which has the solution. Apparently, Mac uses BSD sed and Linux uses GNU sed which have different set of arguments. So provide the extra argument in Mac as shown below.

# Adding the extra argument will work on your Mac
$ sed -i ” ‘s/^192.168.*vm/192.168.1.12 vm/’ /etc/hosts

Leave a comment

Category: Linux,Mac

Find the largest files or directories in Linux

Writing by on Wednesday, 25 of February , 2015 at 8:32 am

Running out of space? To find the biggest files or folders in your Linux environment in descending order, switch to the root folder and then run the du command.

cd /
du -Sh | sort -rh | head -n 20

Mac equivalent is something like

find . -type f -print0 | xargs -0 ls -l | sort -k5,5rn

Leave a comment

Category: Linux

RSyslog – The Basics

Writing by on Wednesday, 3 of December , 2014 at 10:38 pm

Honestly, I found syslog-ng simpler to use once I knew The Basics. However, I also needed to do some testing with rsyslog and hence needed to dig in.

Setup and configure the Host Machine where you will receive the syslog messages.

# 1. Install rsyslog
$ sudo apt-get install rsyslog

# 2. Backup the config file syslog-ng.conf
$ sudo cp /etc/rsyslog.conf /etc/rsyslog.conf.orig

# 3. Edit the config file
$ sudo vi /etc/rsyslog.conf

# 4. Enable TCP/UDP by Uncommenting the following
# provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

# Add a file that will be the destination for your Syslog
local5.* /var/log/my_rsyslog.log

# 5. Restart rsyslog
$ sudo service rsyslog restart

When you configure your Appliance to forward syslog to your Host at local5, you will see the logs in “/var/log/my_rsyslog.log”.

Leave a comment

Category: Linux

SyslogNG – The Basics

Writing by on Wednesday, 22 of October , 2014 at 6:14 pm

You can find enough documentation online and edoceo is a good resource. But the basics of setting up Syslog-NG are as follows.

Setup and configure the Host Machine where you will receive the syslog messages.

# 1. Install syslog-ng
$ sudo apt-get install syslog-ng

# 2. Backup the config file syslog-ng.conf
$ sudo cp /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.orig

# 3. Edit the config file
$ sudo vi /etc/syslog-ng/syslog-ng.conf

# 4. Create a Source, a Destination and bind them together through Log
# Add these in the relevant sections
source s_net { udp(ip(“0.0.0.0”) port(514)); tcp(); };
destination d_somedest { file(“/var/log/somedest.log”); };
log { source ( s_net ); destination ( d_somedest ); };

# 5. Restart syslog-ng
$ sudo service syslog-ng restart

When you configure your Appliance to forward syslog to your Host, you will see the logs in “/var/log/somedest.log”.

Leave a comment

Category: Linux

Escape quote in alias

Writing by on Wednesday, 22 of October , 2014 at 5:25 pm

I wanted to create change the prompt to show the active git branch through an alias.
Changing PS1 as follows would do it as follows:

# Try this in bash to get the git prompt, but how do you alias this?
PS1='[\u@\h \W$(__git_ps1 ” (%s)”)]\$

However I needed to create an alias for it and turns out that if you wanted to escape a single quote you could do it using the following: ‘”‘”‘

# Note here that the entire aliased string needs to be escaped using a quote
alias ingit=’PS1='”‘”‘[\u@\h \W$(__git_ps1 ” (%s)”)]\$'”‘””

Now I can activate the git prompt that I need through an alias that contains a combination of single and double quotes.

Now !!! I wanted to change the IP Address of my DHCP vm in the /etc/hosts file. (Related sed Article)

# something that works
$ sed -i ” ‘s/^192.168.*vm/192.168.1.12 vm/’ /etc/hosts

# i would like to do something like this
$ setvmip 192.168.1.12

# so the escaped version is
alias setvmip=’function _setvmip(){ sudo sed -i “” ‘”‘”‘s/^192.168.*vm/'”‘”‘$@'”‘”‘ vm/'”‘”‘ /etc/hosts ; }; _setvmip’

Leave a comment

Category: Linux

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.