Perl script run a bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script run a bash script
# 1  
Old 07-15-2010
Perl script run a bash script

Hi All,
I think the processing of this is much more complex, so I will explain the whole process by codes.
First,I wrote a expect script named bsim.exp as follows:
Code:
#! /usr/local/bin/expect

set command [ lindex $argv 0 ]
set name [lindex $argv 1]
eval spawn $command

switch -exact $command {
    "bash expecttest.sh" {
        expect "Enter you name:*"
        send "$name\r"
        interact
    }
}

catch "wait -i $spawn_id" reason

# return status code of spawned process
exit [ lindex $reason 3 ]

And a bash script named expecttest.sh who wants to get a input

Code:
#!/bin/bash -x

echo "Enter you name: "
read name


if [ $name == "damon" ];then
    echo "Hi,Damon!"
else
    echo "Oop! you are not my host!"
fi

and I will use a bash script to run all the scripts
Code:
#!/bin/bash -x

./bsim.exp 'bash expecttest.sh' damon
print "test finish.\n";

Now if you run the script upper like this
Code:
bash-3.00# ./test.sh
+ ./bsim.exp 'bash expecttest.sh' damon
spawn bash expecttest.sh
Enter you name:
damon
Hi,Damon!

Now i want to use a perl file to run the test.sh and get the output and print on the screen.
Code:
#!/usr/bin/perl

@lines=`test.sh`

foreach (@lines){
    print $_."\n";
}

there always has some errors or no response.
I don't know what's the probelm of that.

Thanks and Best Regards
Damon

---------- Post updated at 02:02 PM ---------- Previous update was at 11:23 AM ----------

No one can help me??
waiting online

Last edited by Damon sine; 07-15-2010 at 01:41 PM..
# 2  
Old 07-15-2010
why?

qx/script/;

Code:
open OUT, "script|";
print while <OUT>;

This User Gave Thanks to bigearsbilly For This Post:
# 3  
Old 07-16-2010
Hi bigearsbilly,

I don't know what you mean.
Can you give me a detail solution?

---------- Post updated at 03:45 AM ---------- Previous update was at 03:31 AM ----------

Thanks bigearsbilly

I know that you mean,

thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

3. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Shell Programming and Scripting

Run shell script on different machine using perl script

I want to execute my shell script on remote machine using SSH in perl script. Please help me with syntax. (2 Replies)
Discussion started by: james1988
2 Replies

6. Shell Programming and Scripting

Run few perl script in CMD using script

Hi, I have few PERL script which I have to run in CMD. I want to create a new script which will take care of running all these scripts in CMD.:confused: can any one suggest which script will be appropriate to solve my problem. Thanks in advance. (1 Reply)
Discussion started by: arup1980
1 Replies

7. Shell Programming and Scripting

Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Discussion started by: leepet01
5 Replies

8. Shell Programming and Scripting

Run perl script from Unix script

Hello Guys I have to run a perl script from unix one The reason for this is I have to connect to remote server and then execute the perl script. In unix script I am able to connect to remote server without any password via ssh ssh -o 'PasswordAuthentication yes' -o... (5 Replies)
Discussion started by: Pratik4891
5 Replies

9. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

10. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies
Login or Register to Ask a Question