Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, 7 May 2019

How to create ASCII art in shell ?


Visit the site to provide the text and font : 
http://patorjk.com/software/taag/#p=display&h=1&v=1&f=ANSI%20Shadow&t=Jenkins%20%3A%20CI%2FCD

Copy the generated art and paste inside echo command :
echo "
 <Copied text here>
"

Wednesday, 25 April 2018

How to get IP address from a given domain name ?


nslookup <domain_name>

EXAMPLE
nslookup hello.geol.sod.in

Friday, 1 December 2017

How to check processors/cores, memory and disk space using single command ?


Single command to check Processors/cores, Memory and Disk space


# echo "Processor : $(grep "processor" /proc/cpuinfo | wc -l)" && grep "cpu cores" /proc/cpuinfo | awk -F: '{num+=$2} END {print "Cores     :", num}' && echo "Memory    : $(head -1 /proc/meminfo | awk '{print $2}') KB" && echo "$(fdisk -l | grep "Disk /dev" | grep -v "mapper" | awk '{num+=$3} END {print "Disk      :", num}') GB"



Processor : 4
Cores     : 4
Memory    : 8011500 KB
Disk      : 375.8 GB

Monday, 17 July 2017

How to search multiple keywords in a file ?


Use egrep command

egrep -e '^TEXT|^TEXT|TEXT' <file>

egrep -e '^bind| port |pidfile|^logfile' /opt/redis/etc/8000.conf

It will search and give lines corresponding to given keywords :
bind 3200
listen port 800
master pidfile /logs/a.pid
logfile mylogs.log

Sunday, 5 March 2017

How to use a proxy with curl ?


Using proxy with Curl


curl -x 10.190.10.120:8080 http://www.google.co.in

curl -x <Proxy> <Destination>

Tuesday, 7 February 2017

Shell scripting interview questions



What is the output if you execute ./temp.sh 1 2 3 4 5 6 7 8 9 20

Temp.sh

#!/bin/bash
echo $10

10


If we have profile file as given below what is the contents of  /tmp/log.txt in these two cases :
cat profile 2>&1  1>/tmp/log.txt
and
cat profile 1>/tmp/log.txt 2>&1

profile

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin
PATH=$PATH:/opt/freeware/bin:/system/products/openssh/bin:/system/products/sudo/bin:$HOME/bin:.

export PATH


Soft link vs. Hard link



If /tmp/details.txt have read and write  permission to user1.
user1 rights one application by which other  user’s execute it and put their name and address in details.txt file.

How you do it ?




If i execute command "ls" then system display's an error command not found.
But when i do "find -name ls" then it is in /usr/bin/ls.
Why is then this error comes and what is the solution for it ?



There is file in /tmp directory with name test.txt of user USER1 and have the permission 777.
When user USER2 tries to delete that file , he won't able to delete it.
Why ?



What is the output of :
A=321; (A=123); echo $A



If we do not have profile file then what is the contents of /tmp/log.txt in these two cases : 
cat profile  2>&1  1>/tmp/log.txt 
cat profile  1>/tmp/log.txt 2>&1




If I execute temp.sh it is giving an error that not able to execute /var/temp1.sh  may be permission denied.
But if we see the permissions on both files, 777 is there.
Steps to execute it
cd /usr/
./temp.sh


/usr/temp.sh                              
#!/bin/bash
./temp1.sh
echo Hello
 

/var/temp1.sh
#!/bin/bash 
exit 1

Write a one line script using awk  to reverse every string of given line.
awk '{for (i=1;i<=NF;i++){ len=length($i); for(j=len;j>0;j--) { temp=substr($i,j,1); printf("%c",temp)} printf(" ")} printf("\n")}'