Solved

Why does su cause my script to return "not found"  -- 250 points

Posted on 2003-11-10
4
392 Views
Last Modified: 2010-04-21
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/session-logs ]
     then
          v_log=`ls -tr /home/$v_home/.graphon/session-logs/goglobal*.* | tail -1 | cut -d/ -f6`
          echo ====================================================================
          echo "the log file is $v_log"
          v_build=`(grep "client build" /home/$v_home/.graphon/session-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_month-$v_day-$v_time
 
          #------------------------------------------------------------------------
          #Now, remove the listing of home directories; it is no longer needed.
          #------------------------------------------------------------------------
        
                   
    else  echo "Not a graphon user"
            
    fi
   
   done
0
Comment
Question by:jrtanenb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 9718365
The 'su' forks another process.

What you need is a 'su $v_home -c [command to run]'

Where 'command to run' is a script containing the automount and copy stuff you want to do as the user.
0
 
LVL 1

Expert Comment

by:Topace
ID: 9720023
You might be able to just use sudo as well.

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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9720485
With the recent versions of sudo, you can use the NOPASSWD directive if you don't want users to type in a password.
0
 

Author Comment

by:jrtanenb
ID: 9722364
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.  
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question