- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- running a shell script from perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:43 PM
тАО02-16-2006 08:43 PM
I cannot use FTP.
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:52 PM
тАО02-16-2006 08:52 PM
Re: running a shell script from perl
# cat test.sh
ls muthu # error
hostname # log
# chmod u+x test.sh
# cat test.pl
#!/usr/bin/perl
system("./test.sh 1>/tmp/out.log 2>/tmp/err.log");
# perl test.pl
That is it. Change the test.sh to your our script.
--
Muthu
- Tags:
- system
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:55 PM
тАО02-16-2006 08:55 PM
Re: running a shell script from perl
You can "system" call that comes with perl.
Redirect STDOUT and STDERR wherever you want, just like,
system(" /tmp/tmp.sh 1>/tmp/out.log 2>/tmp/err.log");
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:56 PM
тАО02-16-2006 08:56 PM
Re: running a shell script from perl
or
`./test.sh 1>/tmp/test.log 2>&1`
to complete your requirement.
You can use open() in perl to get output from shell command or script execution as well.
open FD, |./script.sh
See this:
http://www.sunsite.ualberta.ca/Documentation/Misc/perl-5.6.1/pod/perlfunc/open.html
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:59 PM
тАО02-16-2006 08:59 PM
Re: running a shell script from perl
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1002042
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 08:59 PM
тАО02-16-2006 08:59 PM
Re: running a shell script from perl
Check this as well,
http://www.tldp.org/LDP/abs/html/wrapper.html#BASHANDPERL
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 09:09 PM
тАО02-16-2006 09:09 PM
Re: running a shell script from perl
http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/f1c5b259748c9d8a/f30c5edf4e8f9970?lnk=st&q=using+shell+script+in+perl&rnum=2#f30c5edf4e8f9970
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 09:26 PM
тАО02-16-2006 09:26 PM
Re: running a shell script from perl
open FD, |./script.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 09:39 PM
тАО02-16-2006 09:39 PM
Re: running a shell script from perl
# cat test.sh
ls muthu
hostname
# perl -e ' open (FD,"|sh test.sh");'
muthu not found
# hostname
PS: You have asked the method which I never used before :). See that link which I sent in prev. thread.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 09:42 PM
тАО02-16-2006 09:42 PM
Re: running a shell script from perl
perl -e ' open (FD,"|sh test.sh");close (FD);'
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 09:55 PM
тАО02-16-2006 09:55 PM
Re: running a shell script from perl
my $sh = Shell->new;
%kp = $sh->(perl -e '\.test.sh') something like this ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 10:02 PM
тАО02-16-2006 10:02 PM
Solution# perl -e '@arr=`./test.sh 2>&1`;print $arr[0] . " " . $arr[1] . "\n";'
2>&1 used to redirect Stand Error mode messages to standard output mode to store those informations into perl array.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 10:02 PM
тАО02-16-2006 10:02 PM
Re: running a shell script from perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 10:05 PM
тАО02-16-2006 10:05 PM
Re: running a shell script from perl
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-16-2006 10:07 PM
тАО02-16-2006 10:07 PM
Re: running a shell script from perl
If you want to run a program within a perl script and capture that program's output, don't use 'system()'. It doesn't provide the program's output.
Instead, a simple choice is to use a backtick syntax:
$output = `/pathto/program`;
You program will run and your perl script will dutifully wait until it's done, placing the program's output in the variable you choose.
Regards!
...JRF...