- Home
- Interview Questions
- Linux Server Administrator
6.
Write a script that will go over all the users on the system and will write the last login date of the user - if we don't have
information about the last login, write "No data for <username >"
#!/bin/sh for i in 'cat /etc/passwd | awk -F: '{print $1; }'' ; do last='last $i | head -n 1'; if [ "$last" != "" ]; then echo 'last $i | head -n 1'; else echo "No data for $i" fi done
7.
How can you check what are the most common commands that you have used in the Linux shell?
You can get this information from the history command and sort it by most used - history | awk '{h[$2]++}END{for(c in h){print h[c] " " c}}' | sort -nr | head.
8.
Write a script that goes to http://www.whatismyip.org/ and writes "Your IP is: <Result from site>".
#!/bin/sh ip='links --source http://www.whatismyip.org/' echo -n "Your IP is: " echo $ip
9.
Create a small calculator in bash script which will have an internal function "dosomething" that will receive a math function
as an input - mycalc 4+4*4.
#!/bin/bash function dosomething { echo "${1}"|bc -l; } dosomething $1
10.
Create a script called KillUserProcs that will get a username as an input and will kill all his processes.
#!/bin/bash kill -9 'ps aux|awk -v var=$1 '$1==var { print $2 }''