Useful Commands

1. To get IP Address of Machine.

#ifconfig eth0| grep "inet addr:"|cut -c '21-35' 

# ifconfig eth0| grep "inet addr:"|awk -F ":" '{print $2}'|cut -d " " -f 1

# ifconfig eth0 |grep "inet addr:"|cut -d: -f2|awk '{print $1}'

2. To get Hardware (MAC) address of Ethernet Device.

#ifconfig eth0| grep "HWaddr"|cut -c '39-55'

#ifconfig eth0| grep "HWaddr"|awk -F " "  '{print $5}'

3. To get load average at 1min, 5min and 15min.

# echo "Load1Min: `uptime |awk -F "load average:" '{print $2}'|cut -d, -f1|sed "s/ //g"`"
Load1min: 5.01

# echo "Load5Min: `uptime |awk -F "load average:" '{print $2}'|cut -d, -f2|sed "s/ //g"`"
Load1min: 2.21

# echo "Load15Min: `uptime |awk -F "load average:" '{print $2}'|cut -d, -f3|sed "s/ //g"`"
Load1min: 1.01

4. To get Memory usage in readable format.

#free -tom | awk '/Total:/ {print "Total memory: "$2" MB\nUsed memory: "$3" MB\nFree memory: "$4" MB"}'

Total Memory: 1503 MB
Used Memory: 2 MB
Free Memory: 1501 MB

Restrict Normal User to run all commands

1. Create user say test.

[root@node ~]# useradd test
[root@node ~]# passwd test
Changing password for user test.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

2. Create a directory say ‘commands’ under user’s home directory.

[test@node ~]$ pwd
[test@node ~]$ mkdir /home/test/commands

3. Modify .bash_profile under user’s home directory.
By default, the environmental variable “PATH” defines the list of directories that contains binary executables which will be called when the user issues a command.

Here we are going to change the PATH variable to user’s home directory/commands folder as follows.

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc

# User specific environment and startup programs
export PATH

4. Now login with test user and try to hit some commands.

[test@node ~]$ ls
-bash: ls: command not found
[test@node ~]$ date
-bash: date: command not found
[test@node ~]$ mv
-bash: mv: command not found
[test@node ~]$ mkdir xyz
-bash: mkdir: command not found
[test@node ~]$ touch ab
-bash: touch: command not found
[test@node ~]$

5. Now create the softlinks of commands which are required for user test to execute in the directory /home/test/commands
Some examples are as follows.

[root@node ~]# ln -s /bin/date /home/test/commands/
[root@node ~]# ln -s /bin/mkdir /home/test/commands/
[root@node ~]# ln -s /bin/touch /home/test/commands/
[root@node ~]# ln -s /bin/ls /home/test/commands/

6. Now re-login as a test user and try above commands.

[root@node ~]# su - test
[test@node ~]$
[test@node ~]$ mkdir abc
[test@node ~]$ date
Sat Jun 10 13:14:27 IST 2017
[test@node ~]$ ls
abc  commands
[test@node ~]$ ls -lrth
total 8.0K
drwxrwxr-x. 2 test test 4.0K Jun 10 13:11 commands
drwxrwxr-x. 2 test test 4.0K Jun 10 13:14 abc
[test@node ~]$

How to create First Job in Jenkins with Subversion.

1. Login to Jenkins URL:

http://<server-ip>:8080, By Default Jenkins works on port 8080

Provide username and password to log in.    

2. Click ‘New Item’ on the left side to create a job.

Enter an Item Name i.e. the Job name, select Freestyle project and click OK to proceed.

Click on ‘This project is parameterized’, click on Add Parameter and select ‘String Parameter’

Now Under String Parameter provides Name as ‘Revision’, Default Value as ‘Head’, and add any Description.
This is needed when you build project with the parameter, it will ask for Revision Number of your choice else will build with Head revision by default.

3. Go to Source Code Management tab.

Select ‘Subversion’, provide the Repository URL, provide credentials who has the access to the Repository URL that you have provided.
Go to the “How to Create Project in SCM-Manager” for more details.

4. Go to the Build Tab.

Click on Add build step and select Execute Shell.
Provide the shell script path or shell script that Jenkins going to execute when you build the project.

For the easy installation of Jenkins please go to the, select your OS ( like RPM or Debian based ) and the follow the steps given.