jrtanenb
asked on
Why does su cause my script to return "not found" -- 250 points
When I include su in the script below (see line 6) it ceases to return data. Instead, it returns 'not found' for every line in the driver file (homelist.$$). homelist contains a list of home directories across over 20 servers. My intention is to run the script as root, have it su to each user listed in the driver file, automount the user's home directory, and grab data from some application log files.
When I run the script as me, it does exactly what I expect but is unable to access those homes where the user has restricted access. When I run this as root and include the su command the script does not behave well.
250 points.
v_rundir=`pwd`
cat $v_rundir/homelist.3968 | while read v_home
do
echo "the current user account is $v_home"
su $v_home
if [ -d /home/$v_home/.graphon/ses sion-logs ]
then
v_log=`ls -tr /home/$v_home/.graphon/ses sion-logs/ goglobal*. * | tail -1 | cut -d/ -f6`
echo ========================== ========== ========== ========== ========== ==
echo "the log file is $v_log"
v_build=`(grep "client build" /home/$v_home/.graphon/ses sion-logs/ $v_log)`
v_build=`echo $v_build |awk '{split($0,FIELD, " "); print FIELD[4] } ' `
echo "the build is: $v_build"
echo "user: $v_home build: $v_build"
echo ========================== ========== ========== ========== ========== ==
#------------------------- ---------- ---------- ---------- ---------- -------
#Now, appent to the final report
#------------------------- ---------- ---------- ---------- ---------- -------
echo "user: $v_home build: $v_build" >> $v_rundir/ggversions.$v_mo nth-$v_day -$v_time
#------------------------- ---------- ---------- ---------- ---------- -------
#Now, remove the listing of home directories; it is no longer needed.
#------------------------- ---------- ---------- ---------- ---------- -------
else echo "Not a graphon user"
fi
done
When I run the script as me, it does exactly what I expect but is unable to access those homes where the user has restricted access. When I run this as root and include the su command the script does not behave well.
250 points.
v_rundir=`pwd`
cat $v_rundir/homelist.3968 | while read v_home
do
echo "the current user account is $v_home"
su $v_home
if [ -d /home/$v_home/.graphon/ses
then
v_log=`ls -tr /home/$v_home/.graphon/ses
echo ==========================
echo "the log file is $v_log"
v_build=`(grep "client build" /home/$v_home/.graphon/ses
v_build=`echo $v_build |awk '{split($0,FIELD, " "); print FIELD[4] } ' `
echo "the build is: $v_build"
echo "user: $v_home build: $v_build"
echo ==========================
#-------------------------
#Now, appent to the final report
#-------------------------
echo "user: $v_home build: $v_build" >> $v_rundir/ggversions.$v_mo
#-------------------------
#Now, remove the listing of home directories; it is no longer needed.
#-------------------------
else echo "Not a graphon user"
fi
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With the recent versions of sudo, you can use the NOPASSWD directive if you don't want users to type in a password.
ASKER
Thank you both (Topace, Tintin) !!!
I love having the resource to get advice from people who are a lot more informed (or maybe just more intelligent) than I.
I am going to give sudo a whirl, also.
I love having the resource to get advice from people who are a lot more informed (or maybe just more intelligent) than I.
I am going to give sudo a whirl, also.
i.e.:
sudo 'command to execute'
This will essentially prompt you for the password ONCE, then sudo will save it for a little while (I think it's like 5 minutes), and during that time, you won't be asked for the password again.
~ace