Operating System - HP-UX
1821244 Members
3007 Online
109632 Solutions
New Discussion юеВ

script to find .netrc file

 
SOLVED
Go to solution
chicuks
Advisor

script to find .netrc file

Hi,
please provide me with a script to find

.netrc file in a system)

please use the below command in the script

find / -name .netrc

this script is only for checking

the script will give an output as

-if there is no .netrc file present in system it will echo "OK"

-if there is one or more than .netrc file(s) then it will echo "NOK" & the number of files present.

regards
chicuks
4 REPLIES 4
Solution

Re: script to find .netrc file

num=$(find / -name .netrc 2>/dev/null | wc -l)

if [ ${num} -eq 0 ] ; then
echo "OK"
else
echo "NOK ${num}"
fi



HTH

Duncan

I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: script to find .netrc file

If you are going to spend hours searching for .netrc files, you might want to save the result from Duncan's find:
find / -name .netrc > netrc_files 2> /dev/null
num=$(wc -l < netrc_files)
TTr
Honored Contributor

Re: script to find .netrc file

The .netrc files are only bad when they are in home directories. It might be quicker to look only there. You also shortcut the loop as soon as you find the first .netrc by using break.

found_netrc=0
cat /etc/passwd |cut -d: -f 6 |
while read homedir
do
if [ -f $homedir/.netrc ]
then
found_netrc=1
break
fi
done
[ $found_netrc = 0 ] && echo OK || echo NOK
Bill Hassell
Honored Contributor

Re: script to find .netrc file

.netrc files are meaningless unless they are in a user's $HOME directory. Don't crush your system performance by looking in / -- that is a total waste of time. Assuming that you have a normal system, all user home directories will be in /home so this one liner will show you all the .netrc files to be concerned about:

ll /home/*/.netrc

If nothing shows then there are no .netrc files in $HOME directories. Now I said 'normal' system, so if you have users with non-standard $HOME directories, you'll have to search using the passwd file. This will look in the exact user $HOME directory:

cut -f6 -d: /etc/passwd | while read HOMEDIR
do
NETRC=$HOMEDIR/.netrc
[ -f $NETRC ] && ll $NETRC || echo "\t$NETRC not present"
done

If .netrc is found, there will be an ll of the file. Otherwise, there is a message that is indented saying that the file is not present.


Bill Hassell, sysadmin