linux - Can any one help me in writing a script for the following scenario -


can 1 me in writing script following scenario!!

  • usera belongs groupa , usera has access "groupa" filesystem
  • userb belongs groupb , userb has access "groupb" filesystem
  • userc belongs groupc , userc has access "groupc" filesystem
  • userd belongs groupd , userd has access "groupd" filesystem

note:- group name , filesystem identical.

help me in writing script, when user logs in, group name identified , execute

df -h */group_name* 

for example:- if usera logs in, need o/p of "df -h /groupa"

[root@server5 ~]# df -h /groupa filesystem            size  used avail use% mounted on /dev/groupa             601t  477t  125t  80% /groupa [root@server5 ~]# 

need write write putting logic, everytime user login system, script need run , produce output on his/her terminal. trying provide information user filesystem utilization. can done putting script inside /etc/profile.d/ directory. user information can taken $user variable , group information can find out "id -gn"

note:- of filesystem given below.

/filesystem/groupe

  • usere belongs groupe , usere has access "/filesystem/groupe" filesystem

i solved problem using below given script:-

grp=$(id -gn) if [ "$grp" == "groupa" ]     df -h /groupa else     if [ "$grp" == "groupb" ]             df -h /groupb     else         if [ "$grp" == "groupc" ]                     df -h /groupc         else             if [ "$grp" == "groupd" ]                             df -h /groupd             else                 if [ "$grp" == "groupe" ]                                     df -h /filesystem/groupe                 fi             fi         fi     fi fi 

there easier way test whether user member of group{a..z} in bash. (note: bash solution since using [[ construct , =~ operator). using id -gn takes care of situation group{a..z} not primary group user, otherwise cause search based on id -gn fail:

#!/bin/bash  grps=$(id -gn)              ## return list of groups of user member  in group{a..z};    ## in groupa, groupb, groupc, ..., groupz      ## test if groupx in list $umg     #  on match disk usage of /groupx     [[ $grps =~ $i ]] && du -hs /$i  done 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -