Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

shell script

Posted on 2014-02-14
5
Medium Priority
?
400 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 750 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 750 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
Suggested Courses

636 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