[Ilugc] [[Need help]] Few *nix questions

  • From: scorpionking.sahil@xxxxxxxxx (sahil साहिल)
  • Date: Mon, 22 Feb 2016 13:08:33 +0530

Namaste Friends,

Recently, I was going through some *nix questions and I stuck on few ones.
Can you guys help me on these?

*These are the questions:*

* Identify which IP address and port the Apache daemon listens on.

Is it a valid solution? I think by scanning on port 80 using nmap we can
find out what ip's apache daemon listens. Perhaps, I could be wrong.
Correct me if I am mistaken.
# nmap -sS -O -p 80 <web server ip>

* Find all IP addresses between your server and www.google.com

* Create an empty directory and change the permissions so that the owner
can execute, read and write, the group can execute and read and the others
cannot do anything.
# mkdir demo && chmod 750 demo

* Print all the lines from /var/log/demon.log having the string ntp and NTP
but not NtP.

* Write a shell script to get the third element delimited by ":" from a
file (passing the file name as an argument to the script) and the format of
the file is same as of /etc/passwd file and then add up all the numbers. Do
not use <awk, sed, cut...>

E.g.:
lightdm:x:112:118:Light Display Manager:/var/lib/lightdm:/bin/false
colord:x:113:121:colord colour management
daemon,,,:/var/lib/colord:/bin/false
hplip:x:114:7:HPLIP system user,,,:/var/run/hplip:/bin/false
pulse:x:115:122:PulseAudio daemon,,,:/var/run/pulse:/bin/false

The third element is: 112 113 114 115
Total is: 454

demo.sh

#!/bin/bash
filename="$1"
sum=0
while IFS=: read -r f1 f2 f3 f4 f5 f6 f7
do
  echo "Third field is = $f3"
  sum=`expr $sum + $f3`
done < $filename
echo "Sum="$sum

I tried to accomplish this by using "IFS" and the script is as follows.
Please review it and if there is any other simple solution then please
share.

I hope such questions will help others too.

Thank you.

-- 

*Regards,Sahil ModGill*

Other related posts: