Posts

Showing posts from March 30, 2014

UNIX shell script that when executed gives you the actual count of regular and special users on the system | UNIX shell script

Problem Write a UNIX shell script that when executed gives you the actual count of regular and special users on the system. #!/bin/bash cat /etc/passwd | cut -d':' -f3 1> total_user.txt sp_user=0 reg_user=0 while read nxt_line do          if [ $nxt_line -ge 500 -a $nxt_line -le 60000 ]          then                 reg_user=`expr $reg_user + 1`          elif [ $nxt_line -eq 0 ]          then                 sp_user=`expr $sp_user + 1`          fi done < total_user.txt echo "total number of special users are: $sp_user" echo "total number of regular users are: $reg_user"

Check file permissions | UNIX shell script

Problem Write a UNIX shell script that accepts exactly two file names as arguments, checks if both the files have the same permissions. If both files have same permissions then print that permission of any one of the file. If the permissions of each file are different, then display the permission of both the files separately. #! /bin/bash # Created by Zain Aftab if [ $# -ne 2 ] then         echo "plz enter only to command line arguments"         exit 0 else f1=$1 f2=$2 set [`ls -l $f1`] f1=$1 set [`ls -l $f2`] f2=$1 if [ $f1 = $f2 ] then echo "The permissions of files are same which are following" echo $f1 else echo "The different permissions"     echo "first file permissions" echo $f1 echo "second file permissions"        echo $f2 fi fi