Solved

shell script

Posted on 2014-02-14
5
391 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
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 26

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

770 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