LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-14-2007, 12:26 PM   #1
saje
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Rep: Reputation: 0
Bash scripting


This script not work.
I want connect from non root user connect to
database
#!/bin/
poveziSQL(){
sleep 5
echo "password "
#password for root
sleep 5
echo "su postgres \n"
sleep 5

echo "psql test"
echo "INSERT INTO test(test) VALUES("test")"
echo"\q"
}|su
 
Old 08-14-2007, 12:30 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Have a look at the "expect" command.
 
Old 08-14-2007, 07:23 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Also, why are you sleeping all the time? Generally no need to do that.
 
Old 08-14-2007, 09:49 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by saje View Post
#!/bin/
That isn't a valid shell. Isn't this supposed to be

Code:
#!/bin/bash
 
Old 08-22-2007, 08:03 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I don't understand the idea behind the script, either. Firstly
root won't need a password to su, secondly you're throwing the
password into the void; if the password were necessary (which
it isn't) you'd want to do
echo "password" | su postgres
No sleeps, and definitely not just an echo in the hopes that
something 2 lines down the script will magically know about it
because it showed on the screen 5 seconds ago



Cheers,
Tink
 
  


Reply



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
new to bash scripting peok Programming 2 07-15-2006 02:46 AM
help on bash scripting Kendo1979 Linux - Newbie 3 05-17-2005 07:10 PM
Bash Scripting Darklight451 Programming 1 10-07-2004 01:48 AM
help with bash scripting spuzzzzzzz Programming 2 09-02-2004 11:42 PM
need help with bash scripting rich2oo1 Programming 2 12-17-2003 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:04 PM.

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
Open Source Consulting | Domain Registration