Solved

shell script

Posted on 2014-02-14
5
398 Views
Last Modified: 2014-03-15
sudo -u postgres -H sh -c "cd /usr/local/src/postgresql-8.2.10;export PERL5LIB=/usr/lib/perl5;export CC="gcc -m32";export LD="ld -melf_i386";export CFLAGS="-m32";export LDFLAGS="-m32";setarch i386"

I am trying to write script to execute the above lines.  How can I script it?  

1. I need to login as postgres account
2. need to set the following variables

export PERL5LIB=/usr/lib/perl5  
export CC="gcc -m32"
export LD="ld -melf_i386"
export CFLAGS="-m32"
export LDFLAGS="-m32"
setarch i386

3.  need to run the following command
./configure --prefix=/pgarc/pgsql --with-perl

4. gmake
0
Comment
Question by:ittechlab
[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
5 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 250 total points
ID: 39860454
Put the commands in a file (vg. MyScrtpt.sh)1

#!/bin/ksh
#
# Script: MyScrtpt.sh
#
# 1. I need to login as postgres account

cd /usr/local/src/postgresql-8.2.10

sudo  su -  postgres    #<= Here goes the postgres account ...

# 2. need to set the following variables

export PERL5LIB=/usr/lib/perl5  
export CC="gcc -m32"
export LD="ld -melf_i386"
export CFLAGS="-m32"
export LDFLAGS="-m32"
setarch i386

# 3.  need to run the following command

./configure --prefix=/pgarc/pgsql --with-perl

# 4. gmake 

gmake          #<= What goes here ????

exit

Open in new window

Then make it executable:
chmod +x MyScrtpt.sh

Open in new window

0
 

Author Comment

by:ittechlab
ID: 39860484
[root@rhel5 scripts]# ./myscript.sh
[postgres@rhel5 ~]$

when I run this script its su - postgres and waits there.

[postgres@rhel5 ~]$ exit
logout
-sh-3.2#

-sh-3.2#exit

then it is started to run the ./configure part...

why this happens.
0
 

Author Comment

by:ittechlab
ID: 39860486
my concern is it should run as soon as su - postgres.
0
 
LVL 5

Expert Comment

by:Dave Gould
ID: 39861396
The sudo should be outside the script and the script run by the sudo command.

ie comment out the sudo line in your script and then run the script using

sudo -u postgres myscript.sh
0
 
LVL 27

Assisted Solution

by:skullnobrains
skullnobrains earned 250 total points
ID: 39886569
try this instead of your su line

if test `whoami` != postgres
then sudo su postgres -c "/bin/sh $0"
  exit $?


or alternatively

cat <<EOF |sudo su postgres -c "/bin/sh"
....
EOF
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

696 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