CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
System command not executing

 



manoharcr
New User

Feb 23, 2010, 8:58 PM

Post #1 of 3 (337 views)
System command not executing Can't Post

Hi all,
I am writing a small script which takes the backup of my database. It looks as follows if i manually doing in shell
1. /etc/init-d/ourTool-tomcat stop

2. su - ourToolUser ( prompt changes to indicate the new user, and current directory changes to/var/lib/OurToolInstallationFOlder)

3. pg_dump fp_database 1 > /home/user1/database1.dump


Usually when after issueing the second command in normal shell, it changes the user like
ourTooluser@server1:~>
In this prompt i need to enter 3 command so that it will take the database dump. But if i am wring same thing in perl using system command, like
system(/etc/init-d/ourTool-tomcat stop);
system(su - ourToolUser);
system(pg_dump fp_database 1 > /home/user1/database1.dump);

After executing second line it just stops and control goes to
ourTooluser@server1:~> and it will never execute the third line, any one can pls suggest how it can be achieved in perl??


rovf
Veteran

Feb 24, 2010, 1:05 AM

Post #2 of 3 (334 views)
Re: [manoharcr] System command not executing [In reply to] Can't Post

Not really a Perl question, but ....

su called in the way you are doing, starts a new interactive shell. In your case, it would be more appropriate to use the -c option of su. See the man su for details.

BTW: If you absolutely *want* to run a sub shell (but why would you?), see perldoc Net::Telnet.


7stud
Enthusiast

Feb 24, 2010, 3:01 AM

Post #3 of 3 (330 views)
Re: [rovf] System command not executing [In reply to] Can't Post


Quote
su called in the way you are doing, starts a new interactive shell.

...and if that's the case, system() won't return until the interactive shell has finished executing. system() *waits* until whatever program you are executing returns.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives