Michael Quick wrote:
> Hi,
> Grr, I've been bit by the script bug.  Just found out the hard way that 
> you can't use 'su -c' in a script if you are trying to grab it from a 
> webpage and run it.  I get the error "standard in must be a tty".  Need 
> this to work for end-users, any ideas  or workarounds?  Anyone see this 
> before ?  Thanks in advance.

If you need to respond to a passwd prompt then you will need Expect or
Perl Expect handle the prompt.   The passwd command does not expect data
from standard in, but from a tty device.   An alternative is to use sudo
as it has the option of taking a passwd on standard in.

Jim Doherty

> 
> EXAMPLE:
> [EMAIL PROTECTED] Desktop]$ *curl http://somehost.com/reinstall_package.sh | 
> bash*
>   % Total    % Received % Xferd  Average Speed   Time    Time     Time  
> Current
>                                  Dload  Upload   Total   Spent    Left  
> Speed
> 100  4313  100  4313    0     0  36125      0 --:--:-- --:--:-- --:--:-- 
> 3234k
> checking credentials ...
> Please enter the Administrator (root) password.
> *standard in must be a tty*
> 
> 
> CODE :
> # --- Check for 'Root' credentials
> CMDLN_ARGS="$@"                          # Command line arguments for 
> this script
> export CMDLN_ARGS
> # Run this script as root if not already.
> # if passed silent option, will exit on failure.
> chk_root () {
> 
>     temp_cond="$1"
>     if [ ! $( id -u ) -eq 0 ]; then
>         if [ "$temp_cond" != "silent" ] ;then
>             echo "Please enter the Administrator (root) password."
>             exec su -c "${0} ${CMDLN_ARGS}" # Call this prog as root
>             exit ${?}                       # sice we're 'execing' 
> above, we wont reach this exit
>                                             # unless something goes wrong.
>         else
>             # the 'silent' option has been set -  just exit.
>             echo "root privilages have not been met ."
>             exit 1
>         fi
>     fi
> 
> }
>

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org          
   
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug                           
Upcoming Meetings (6pm - 8pm)                         MHVLS Auditorium          
                              
  Dec 5 - Open Source Show and Tell
  Jan 2 - TBD
  Feb 6 - DBUS
  Mar 5 - Setting up a platform-independent home/small office network using 
Linux

Reply via email to