LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-25-2011, 11:19 AM   #1
csravi88
LQ Newbie
 
Registered: Jun 2010
Distribution: RHEL, CentOS, Debian, AIX
Posts: 15

Rep: Reputation: 0
Echo "password" to su


Hi,

I have to run "pppd call idea" command from root shell every time to connect to internet from mobile. Now i want a script so that i just run it to connect. someting like :

#!/bin/sh
echo "password" --stdin | su -
pppd call idea

but its showing error that "standard in must be a tty".

why is this. using CentOS 5.5

Thanks,
Ravi
 
Old 02-25-2011, 11:24 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
it's correct to say that. What you want to do is pretty horrible, don't do it. You can use sudoers to allow a normal user to execute a single command if necessary. see the sudo / sudoers manpage for more details.
 
Old 02-25-2011, 12:42 PM   #3
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Also, look at the /etc/rc.d/rc.local file. That's a script that is automatically run by the init script, as "root," before your system starts the X-server. It's designed for stuff like you want to do, Here, for example is my rc.local script for this laptop:
Code:
$ sudo cat /etc/rc.d/rc.local
[sudo] password for Peter: 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
local_dir="/etc/rc.d/"
touch /var/lock/subsys/local
#-----------------------------

# Turn off all output
#exec &>/dev/null

# Load the local function definitions
__local=T
. ${local_dir}/rc.local_functions
echo
echo -----------------------------------------------------
echo Starting $0

# Connect to the TSS3 network if it's available
connect_to TSS3

# Activate and mount any available, unmounted, volume groups with mount points in /etc/fstab
vg_activate

# Mount any "noauto" devices listed in /etc/fstab that exist and are not already mounted
mount_noauto

# Mount any "noauto" cifs devices
mount_cifs

# Mount up to max_loop ISO files located in /ISO under /mnt/ISO/
mount_iso
echo -----------------------------------------------------
echo
<edit>
Oh, note that that script uses my rc.local_functions. Since you're doing network connection stuff, here's the part of that script that connects my laptop to my local network. (Note the sucmd function that let's me run the privileged stuff in the other functions if, for some reason, I need to rerun one of them during without rebooting.)
Code:
$ cat /etc/rc.d/rc.local_functions
#!/bin/bash
#############################################################################
#
# Define some terminal control codes
# See man console_codes for terminal display code descriptions.
#
#############################################################################
csi="$(echo -en \\e)[0;"
red="${csi}1;31m"
green="${csi}1;32m"
blue="${csi}34m"
cyan="${csi}36m"
white="${csi}37m"
reset="${csi}39m"

#############################################################################
#
# Return an empty string if called from rc.local (if rc.local sets __local),
# otherwise return "sudo"
#
#############################################################################
sucmd() {
  local error_code
  if [[ "${__local}" = "T" ]]
  then
    sucmd=
  else
    sucmd="sudo"
  fi
  echo -n ${blue}
  ${sucmd} $*
  error_code=$?
  echo -n ${reset}
  return ${error_code}
}

#############################################################################
#
# Connect to the specified network if it's available
#
# Arguments:
#  $1 - Access point
#  $2 - Passphrase (If blank, use contents of /root/.connect_passphrase)
#  $3 - Connection type {unprotected|wep|wpa} Default: wpa
#       Note: Only passphrase WEP and WPA encription is supported
#             by this script
#
#############################################################################
connect_to() {
  local we type pass i
# Get the list of available access points
  we=$(cnetworkmanager --we)
  if [ -z "${we}" ]
  then 
    echo "${red}No wireless devices are available on this system.${reset}"
    return
  fi
  [ -z "${pass}" ] && pass=$(cat /root/.connect_passphrase)
  type=$3
  [ -z "${type}" ] && type=wpa
  case ${type,*} in
    unprotected)pass="";;
    wep) type=wep-pass;;
    *) type=wpa-pass;;
  esac
  echo -n "${blue}Connecting to ${1}"
  cnetworkmanager -C ${1} --${type} ${pass} &>/dev/null &
  pid=$!
  if [ $? -ne 0 ]
  then
    echo " ${red}Unable to connect to ${1}.${reset}"
  else
    for ((i=1; i<6; i=++i))
    do
      sleep 1
      echo -n " ."
    done
    echo
    echo "${green}Connected to ${1}${reset}"
#    sleep 5
  fi
  disown ${pid}
}
[...]

Last edited by PTrenholme; 02-25-2011 at 12:53 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unique password for "update" and "synaptic" and "apt-get" SaintDanBert Linux - Security 1 09-17-2010 05:53 AM
echo mypage.htm | mutt -s "hello news" myemail@gmail.com frenchn00b Linux - General 16 04-20-2009 02:21 AM
exec() echo "password" | cryptsetup shakeshar Programming 1 03-20-2009 10:30 AM
Supplying "password" to "ssh" command paragkalra Linux - Networking 1 07-31-2008 06:19 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 03:14 PM


All times are GMT -5. The time now is 01:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration