ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

hi Monks
when i run the command "su postgres" it takes me to $ shell(only $) sorry I am new to perl and linux.
i want to run few commands here but system,exec,backticks wont run untill I come out from this shell bye manually typing "Exit"
please suggest something
  • Comment on to run a command from $ shell in perl program

Replies are listed 'Best First'.
Re: to run a command from $ shell in perl program
by GrandFather (Saint) on Oct 20, 2011 at 07:32 UTC

    Have you looked at DBI and DBD::Pg? Do they allow you to do the database stuff you need without spawning a shell process?

    True laziness is hard work
Re: to run a command from $ shell in perl program
by anneli (Pilgrim) on Oct 20, 2011 at 05:18 UTC

    You are getting the Postgres shell, not a Perl shell. You cannot use Perl at the Postgres shell.

    I'm wrong, you're just at the postgres user's shell. Maybe you want to use psql to use Postgres.

Re: to run a command from $ shell in perl program
by DrHyde (Prior) on Oct 20, 2011 at 09:54 UTC
    If you're being asked to write code and work with databases on Unix but don't know how to use a Unix shell, then you need to ask your boss for some training.
      How about checking your PATH environment ?

      You logged in unix system with postgres super user account and you run perl script on the console but it didn't work as your ordinary account get worked it well, is this your situation?

      In that case, which command and PATH env will help you, I guess. Good luck.

Re: to run a command from $ shell in perl program
by pvaldes (Chaplain) on Oct 20, 2011 at 12:10 UTC
    when i run the command "su postgres"

    to do what?...

    want to run few commands here but system,exec,backticks wont run

    Well, first of all because these are perl commands, but you are in a shell that is a different program. If you want to run perl from here then use a perl script (or perl one liners). Second question, of course you had login in the shell as the plain user postgres, not as superuser root. This user don't have superpowers normally outside postgres databases, so if you use system for example, you have the powers of postgresql user, no more, and some system calls and commands (that are exclusive of root) will fail. To try to use postgres for things unrelated with postgres DB management is probably unwise and if "su" don't ask for a password in "su postgres" you are doing wrong.

    if you still think that you need a graphic desktop for postgres user take a look to "adduser", (not necessary and not recommended, but if this make you feel better at the start, you can use it). If you need a graphic access to the database use i.e. pgadmin3, (but psql is perfect for me)