Solved

shell script

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
digital ocean web console access ? does it use port 22 4 105
SMB share across internet 15 110
Zimbra and Renewing SSL Certficate 9 53
Shrink Linux Swap File Size CentOS 10 66
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

734 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