Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fuser -u script 1

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi all,

I am currently putting a ksh script together that allows the standard user to see who is currently in a Database table. At the moment I have the following put together:

clear

trap "" 1 2 3

until [ -n "$validchoice" ]
do
#
# Menu
#
echo '

Check whos on before closing down

1. I am closing off Sales Ledger

2. I am closing off Nominal/General Ledger

3. I am closing off Stock

4. I am closing off Purchase Ledger

Q. Quit/Exit

Please select one of the above (1-4 or Q) : \c'

#
# Read and Process Selection
#

read choice
echo

case "$choice"
in

1) clear
## mong=`fuser -u /usr/cs3/sysmprc/sl* | awk -F: '{print$3}'`
mong=`fuser -u /usr/cs3/sysmprc/sl*`
echo $mong | awk -F: '{print$3}'
validchoice=TRUE;;
2) clear
fuser -u /usr/cs3/sysmprc/nl* | awk '{print$3}'
validchoice=TRUE;;
3) clear
fuser -u /usr/cs3/sysmprc/st* | awk '{print$3}'
validchoice=TRUE;;
4) clear
fuser -u /usr/cs3/sysmprc/pl* | awk '{print$3}'
validchoice=TRUE;;
Q) clear
trap 1 2 3
exit;;
q) clear
trap 1 2 3
exit;;

*) echo "\n\nTry reading the options ";;
esac
done

This works fine. Except I need to get just the usernames against each table. Look this up against the /etc/passwd and bring back to the screen the usernames 'realname'.

Any Ideas?

Thanks in advance.

( "To become Wise, first you must ask Questions")
 
Try something like (untested):
Code:
echo $mong | awk -F: '{print$3}' | while read user
do 
   grep "^$user:" /etc/paswd | cut -d: -f5
done
 
BTW, if you don't need the full power of 'awk', 'cut' is much lighter weight.
 
Thanks ericbrunson. Will give it a go.


( "To become Wise, first you must ask Questions")
 
Tried tht script enhancement. Unfortunately All I can get is a big streaming list of files and users touching on them. But then will not do anything else.

Has anyone else got any ideas?


( "To become Wise, first you must ask Questions")
 
Unless my environment is unique, the fuser tool is a bit tricky to script using wildcards for the filenames. What I typically have to do is run the fuser command and redirect STDOUT and STDERR to a temporary text file, then run my test against those results.

Try running something like this:
# cd /usr/cs2/sysmpcr
# fuser -u sl* | more

Compare that to:
# cd /usr/cs2/sysmpcr
# fuser -u sl* >fulist 2>&1
# more fulist

In my environment, unless I redirect to a file, the STDOUT and STDERR appear to display to my screen "out of sync", which makes it a bear to script.
 
that's certaintly true under Solaris - you definetely need to map stderr to stdout.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks motoslide. Forgot to mention I am writing this script for use on AIX 4.3.3 ML9



( &quot;To become Wise, first you must ask Questions&quot;)
 
Has anyone else got any suggestions?

( &quot;To become Wise, first you must ask Questions&quot;)
 
Can you post the output of this command:
fuser -u /usr/cs3/sysmprc/sl*
and the expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The expected out put of the command is a list of each file then the PID then if a user is touching against it.


( &quot;To become Wise, first you must ask Questions&quot;)
 
Again, what is the actual output of the fuser -u command on your system ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sorry heere is the actual output from the fuser -u command:

sl.out:
sl.sql:
slanalm.dat:
slanalm.idx:
slbankm.dat:
slbankm.idx:
slbataudm.dat:
slbataudm.idx:
slcadvm.dat:
slcadvm.idx:
slcasham.dat:
slcasham.idx:
slcashbm.dat:
slcashbm.idx:
slcashdm.dat:
slcashdm.idx:
slcashem.dat:
slcashem.idx:
slcashm.dat: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slcashm.idx: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slcashmcm.dat:
slcashmcm.idx:
slcashptm.dat:
slcashptm.idx:
slcashwm.dat:
slcashwm.idx:
slccnvdm.dat:
slccnvdm.idx:
slcontm.dat:
slcontm.idx:
slctaxm.dat:
slctaxm.idx:
slctxtm.dat:
slctxtm.idx:
slcurrm.dat:
slcurrm.idx:
slcustam.dat:
slcustam.idx:
slcustcm.dat:
slcustcm.idx:
slcustem.dat: 51708(unit5nzb) 180272(ccsrvnzb)
slcustem.idx: 51708(unit5nzb) 180272(ccsrvnzb)
slcusteum.dat:
slcusteum.idx:
slcustgm.dat:
slcustgm.idx:
slcusthlm.dat:
slcusthlm.idx:
slcusthm.dat:
slcusthm.idx:
slcusthsm.dat:
slcusthsm.idx:
slcustim.dat:
slcustim.idx:
slcustlm.dat:
slcustlm.idx:
slcustlocm.dat:
slcustlocm.idx:
slcustm.dat: 51708(unit5nzb) 70482(unit5dzy) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slcustm.idx: 51708(unit5nzb) 70482(unit5dzy) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slcustom.dat:
slcustom.idx:
slcustpm.dat:
slcustpm.idx:
slcusttm.dat:
slcusttm.idx:
slddebm.dat:
slddebm.idx:
slintdm.dat:
slintdm.idx:
slinthem.dat:
slinthem.idx:
slinthm.dat:
slinthm.idx:
slinvagm.dat:
slinvagm.idx:
slinvam.dat:
slinvam.idx:
slinvcm.dat:
slinvcm.idx:
slinvdem.dat:
slinvdem.idx:
slinvem.dat:
slinvem.idx:
slinvfam.dat:
slinvfam.idx:
slinvgm.dat:
slinvgm.idx:
slinvhem.dat:
slinvhem.idx:
slinvim.dat:
slinvim.idx:
slinvm.dat: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slinvm.idx: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slinvvcm.dat:
slinvvcm.idx:
slinvxm.dat: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slinvxm.idx: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slitemam.dat:
slitemam.idx:
slitemcm.dat:
slitemcm.idx:
slitemem.dat:
slitemem.idx:
slitemgm.dat:
slitemgm.idx:
slitemim.dat:
slitemim.idx:
slitemm.dat: 43140(unit5jms) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slitemm.idx: 43140(unit5jms) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slitemmcm.dat:
slitemmcm.idx:
sljrnm.dat: 43140(unit5jms) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
sljrnm.idx: 43140(unit5jms) 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slletaudm.dat:
slletaudm.idx:
sllettm.dat:
sllettm.idx:
sln07598.T09:
sln10586.T06:
sln54526.T05:
sln61008.T08:
sln73902.T03:
sln85328.T09:
slpaymm.dat:
slpaymm.idx:
slpaytm.dat:
slpaytm.idx:
slrdlstm.dat:
slrdlstm.idx:
slrefdem.dat:
slrefdem.idx:
slrefdm.dat: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slrefdm.idx: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slrefdmcm.dat:
slrefdmcm.idx:
slremhm.dat:
slremhm.idx:
slremm.dat:
slremm.idx:
slrhlstm.dat:
slrhlstm.idx:
slsupsm.dat:
slsupsm.idx:
sltextm.dat:
sltextm.idx:
slvlexm.dat:
slvlexm.idx:
slxrefm.dat: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slxrefm.idx: 117422(unit5sjh) 147838(unit5dzy) 167660(unit5azw)
slxrefmcm.dat:
slxrefmcm.idx:
slxrefrm.dat:
slxrefrm.idx:



( &quot;To become Wise, first you must ask Questions&quot;)
 
A starting point:
1) clear
fuser -u /usr/cs3/sysmprc/sl* | nawk -F: '
BEGIN{
FS=":";while(getline<"/etc/passwd">0)a[$1]=$5
FS="[:() \t]+"
}
NF>2{
for(i=3;i<=NF;i+=2) print $1,$i,a[$i]
}'
validchoice=TRUE;;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV. One thing tried a man nawk but got no entries for this command. I take it awk will do?


( &quot;To become Wise, first you must ask Questions&quot;)
 
Just tried that part of yor program this is the output I now get from it:

/usr/cs3/sysmprc/sl.out:
/usr/cs3/sysmprc/sl.sql:
/usr/cs3/sysmprc/slanalm.dat:
/usr/cs3/sysmprc/slanalm.idx:
/usr/cs3/sysmprc/slbankm.dat:
/usr/cs3/sysmprc/slbankm.idx:
/usr/cs3/sysmprc/slbataudm.dat:
/usr/cs3/sysmprc/slbataudm.idx:
/usr/cs3/sysmprc/slcadvm.dat:
/usr/cs3/sysmprc/slcadvm.idx:
/usr/cs3/sysmprc/slcasham.dat:
/usr/cs3/sysmprc/slcasham.idx:
/usr/cs3/sysmprc/slcashbm.dat:
/usr/cs3/sysmprc/slcashbm.idx:
/usr/cs3/sysmprc/slcashdm.dat:
/usr/cs3/sysmprc/slcashdm.idx:
/usr/cs3/sysmprc/slcashem.dat:
/usr/cs3/sysmprc/slcashem.idx:
/usr/cs3/sysmprc/slcashm.dat: (unit5azw)
/usr/cs3/sysmprc/slcashm.idx: (unit5azw)
/usr/cs3/sysmprc/slcashmcm.dat:
/usr/cs3/sysmprc/slcashmcm.idx:
/usr/cs3/sysmprc/slcashptm.dat:
/usr/cs3/sysmprc/slcashptm.idx:
/usr/cs3/sysmprc/slcashwm.dat:
/usr/cs3/sysmprc/slcashwm.idx:
/usr/cs3/sysmprc/slccnvdm.dat:
/usr/cs3/sysmprc/slccnvdm.idx:
/usr/cs3/sysmprc/slcontm.dat:
/usr/cs3/sysmprc/slcontm.idx:
/usr/cs3/sysmprc/slctaxm.dat:
/usr/cs3/sysmprc/slctaxm.idx:
/usr/cs3/sysmprc/slctxtm.dat:
/usr/cs3/sysmprc/slctxtm.idx:
/usr/cs3/sysmprc/slcurrm.dat:
/usr/cs3/sysmprc/slcurrm.idx:
/usr/cs3/sysmprc/slcustam.dat:
/usr/cs3/sysmprc/slcustam.idx:
/usr/cs3/sysmprc/slcustcm.dat:
/usr/cs3/sysmprc/slcustcm.idx:
/usr/cs3/sysmprc/slcustem.dat: (unit5nzb)
/usr/cs3/sysmprc/slcustem.idx: (informix)(unit5nzb)
/usr/cs3/sysmprc/slcusteum.dat:
/usr/cs3/sysmprc/slcusteum.idx:
/usr/cs3/sysmprc/slcustgm.dat:
/usr/cs3/sysmprc/slcustgm.idx:
/usr/cs3/sysmprc/slcusthlm.dat:
/usr/cs3/sysmprc/slcusthlm.idx:
/usr/cs3/sysmprc/slcusthm.dat:
/usr/cs3/sysmprc/slcusthm.idx:
/usr/cs3/sysmprc/slcusthsm.dat:
/usr/cs3/sysmprc/slcusthsm.idx:
/usr/cs3/sysmprc/slcustim.dat:
/usr/cs3/sysmprc/slcustim.idx:
/usr/cs3/sysmprc/slcustlm.dat:
/usr/cs3/sysmprc/slcustlm.idx:
/usr/cs3/sysmprc/slcustlocm.dat:
/usr/cs3/sysmprc/slcustlocm.idx:
/usr/cs3/sysmprc/slcustm.dat: (unit5jms)(ccsrvrvs)(unit5sjh)(unit5dzy)(unit5nzb)(unit5azw)
/usr/cs3/sysmprc/slcustm.idx: (unit5jms)(ccsrvrvs)(unit5sjh)(unit5dzy)(unit5nzb)(unit5azw)
/usr/cs3/sysmprc/slcustom.dat:
/usr/cs3/sysmprc/slcustom.idx:
/usr/cs3/sysmprc/slcustpm.dat:
/usr/cs3/sysmprc/slcustpm.idx:
/usr/cs3/sysmprc/slcusttm.dat:
/usr/cs3/sysmprc/slcusttm.idx:
/usr/cs3/sysmprc/slddebm.dat:
/usr/cs3/sysmprc/slddebm.idx:
/usr/cs3/sysmprc/slintdm.dat:
/usr/cs3/sysmprc/slintdm.idx:
/usr/cs3/sysmprc/slinthem.dat:
/usr/cs3/sysmprc/slinthem.idx:
/usr/cs3/sysmprc/slinthm.dat:
/usr/cs3/sysmprc/slinthm.idx:
/usr/cs3/sysmprc/slinvagm.dat:
/usr/cs3/sysmprc/slinvagm.idx:
/usr/cs3/sysmprc/slinvam.dat:
/usr/cs3/sysmprc/slinvam.idx:
/usr/cs3/sysmprc/slinvcm.dat:
/usr/cs3/sysmprc/slinvcm.idx:
/usr/cs3/sysmprc/slinvdem.dat:
/usr/cs3/sysmprc/slinvdem.idx:
/usr/cs3/sysmprc/slinvem.dat:
/usr/cs3/sysmprc/slinvem.idx:
/usr/cs3/sysmprc/slinvfam.dat:
/usr/cs3/sysmprc/slinvfam.idx:
/usr/cs3/sysmprc/slinvgm.dat:
/usr/cs3/sysmprc/slinvgm.idx:
/usr/cs3/sysmprc/slinvhem.dat:
/usr/cs3/sysmprc/slinvhem.idx:
/usr/cs3/sysmprc/slinvim.dat:
/usr/cs3/sysmprc/slinvim.idx:
/usr/cs3/sysmprc/slinvm.dat: (unit5azw)
/usr/cs3/sysmprc/slinvm.idx: (unit5azw)
/usr/cs3/sysmprc/slinvvcm.dat:
/usr/cs3/sysmprc/slinvvcm.idx:
/usr/cs3/sysmprc/slinvxm.dat: (unit5azw)
/usr/cs3/sysmprc/slinvxm.idx: (unit5azw)
/usr/cs3/sysmprc/slitemam.dat:
/usr/cs3/sysmprc/slitemam.idx:
/usr/cs3/sysmprc/slitemcm.dat:
/usr/cs3/sysmprc/slitemcm.idx:
/usr/cs3/sysmprc/slitemem.dat:
/usr/cs3/sysmprc/slitemem.idx:
/usr/cs3/sysmprc/slitemgm.dat:
/usr/cs3/sysmprc/slitemgm.idx:
/usr/cs3/sysmprc/slitemim.dat:
/usr/cs3/sysmprc/slitemim.idx:
/usr/cs3/sysmprc/slitemm.dat: (ccsrvrvs)(unit5sjh)(unit5dzy)(unit5azw)
/usr/cs3/sysmprc/slitemm.idx: (ccsrvrvs)(unit5sjh)(unit5dzy)(unit5azw)
/usr/cs3/sysmprc/slitemmcm.dat:
/usr/cs3/sysmprc/slitemmcm.idx:
/usr/cs3/sysmprc/sljrnm.dat: (unit5dzy)(unit5azw)
/usr/cs3/sysmprc/sljrnm.idx: (unit5dzy)(unit5azw)
/usr/cs3/sysmprc/slletaudm.dat:
/usr/cs3/sysmprc/slletaudm.idx:
/usr/cs3/sysmprc/sllettm.dat:
/usr/cs3/sysmprc/sllettm.idx:
/usr/cs3/sysmprc/sln07598.T09:
/usr/cs3/sysmprc/sln10586.T06:
/usr/cs3/sysmprc/sln54526.T05:
/usr/cs3/sysmprc/sln61008.T08:
/usr/cs3/sysmprc/sln73902.T03:
/usr/cs3/sysmprc/sln85328.T09:
/usr/cs3/sysmprc/slpaymm.dat:
/usr/cs3/sysmprc/slpaymm.idx:
/usr/cs3/sysmprc/slpaytm.dat:
/usr/cs3/sysmprc/slpaytm.idx:
/usr/cs3/sysmprc/slrdlstm.dat:
/usr/cs3/sysmprc/slrdlstm.idx:
/usr/cs3/sysmprc/slrefdem.dat:
/usr/cs3/sysmprc/slrefdem.idx:
/usr/cs3/sysmprc/slrefdm.dat: (unit5azw)
/usr/cs3/sysmprc/slrefdm.idx: (unit5azw)
/usr/cs3/sysmprc/slrefdmcm.dat:
/usr/cs3/sysmprc/slrefdmcm.idx:
/usr/cs3/sysmprc/slremhm.dat:
/usr/cs3/sysmprc/slremhm.idx:
/usr/cs3/sysmprc/slremm.dat:
/usr/cs3/sysmprc/slremm.idx:
/usr/cs3/sysmprc/slrhlstm.dat:
/usr/cs3/sysmprc/slrhlstm.idx:
/usr/cs3/sysmprc/slsupsm.dat:
/usr/cs3/sysmprc/slsupsm.idx:
/usr/cs3/sysmprc/sltextm.dat:
/usr/cs3/sysmprc/sltextm.idx:
/usr/cs3/sysmprc/slvlexm.dat:
/usr/cs3/sysmprc/slvlexm.idx:
/usr/cs3/sysmprc/slxrefm.dat: (unit5azw)
/usr/cs3/sysmprc/slxrefm.idx: (unit5azw)
/usr/cs3/sysmprc/slxrefmcm.dat:
/usr/cs3/sysmprc/slxrefmcm.idx:
/usr/cs3/sysmprc/slxrefrm.dat:
/usr/cs3/sysmprc/slxrefrm.idx:
167660
165816
96770
160694
166178
96770
160694
166178
167660
167660
122198
161310
122198
161310
161310
161310
167660
167660

I used awk and NOT nawk.

( &quot;To become Wise, first you must ask Questions&quot;)
 
Tried it again with awk and got the same output.


( &quot;To become Wise, first you must ask Questions&quot;)
 
Works for me with your supplied fuser -u output.
Either the AIX implementation of awk is a very old one or you make a mistake when copy/paste my suggested code.
If you have gawk, try it.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
This is what I pasted into the script:

1) clear
echo
echo " Please Wait! Getting Usernames"
echo
fuser -u /usr/cs3/sysmprc/sl* | awk -F: '
BEGIN{
FS=":";while(getline<"/etc/passwd">0)a[$1]=$5
FS="[:() \t]+"
}
NF>2{
for(i=3;i<=NF;i+=2) print $1,$i,a[$i]
}'
validchoice=TRUE;;

I'll see if I have gawk. But I doubt it some how.


( &quot;To become Wise, first you must ask Questions&quot;)
 
This should work with an old awk:
1) clear
echo
echo " Please Wait! Getting Usernames"
echo
fuser -u /usr/cs3/sysmprc/sl* | awk -F: '
BEGIN{while(getline<"/etc/passwd">0)a[$1]=$5}
/\(/{n=split($2,u,"(")
for(i=2;i<=n;++i){
sub(/\).*/,"",u);print $1,u,a[u]
} }'
validchoice=TRUE;;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top