473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing parameters to .sh file from a perl file

Dear Friends,

I have a perl script abc.pl.I will be running this script with an parameter .The same parameter value i would like to pass to the shell script (The shell script is inside perl script ).Is it possible.Can any body throw light on this ?.

Example :perl abc.pl arg1

content of abc.pl
--------------------
{
sh hello.sh arg1
}

Thanks in advance
Jayakumar
Jun 23 '07 #1
8 2786
KevinADC
4,059 Expert 2GB
The @ARGV array holds the arguments you send a perl program from the command line. So if you do this:

Expand|Select|Wrap|Line Numbers
  1. perl myprogram.pl arg1
in the myprogram.pl script you can get the argument like so:

Expand|Select|Wrap|Line Numbers
  1. my $argv1 = $ARGV[0];
now use $argv1 however needed in your script.
Jun 23 '07 #2
Hi,

I tried this ...I am in unix machine A
(Here arg is 888).
#perl abc.pl 888

my $empno1 = $ARGV[0];
print "$empno1\n";
use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die',Prompt => '/\$ $/i');
$telnet->open($host);
$telnet->login($username,$passwd);
print $telnet->cmd('sh user.sh $empno1'); ##Connected to another UNIX m/c B.

I can assign parameter to perl and inside perl i can able to get the value.But how to pass the parameter value to another shell script.Script is in another unix machine.Can anybody help in this ?

thanks
Jayakumar
Jun 25 '07 #3
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. my $empno1 = $ARGV[0];
  2. print "$empno1\n";
  3. use Net::Telnet;
  4. $telnet = new Net::Telnet ( Timeout=>10,Errmode=>'die',Prompt => '/\$ $/i');
  5. $telnet->open($host);
  6. $telnet->login($username,$passwd);
  7. my $cmd = "sh user.sh $empno1";
  8. print $telnet->cmd($cmd); ##Connected to another UNIX m/c B.
Jun 25 '07 #4
Kevin !

Thanks for you timely help.

By
jayakumar
Jun 25 '07 #5
Question.

I've read the thread but not sure I understand. I've got a similar problem and very much amature to PERL. (less than a week).

I've got 3 different parameter values that I've defined in the perl script and need to pass them to a shell script for use. (Need to do a diff on 2 files and all the perl stuff I've found on that topic is way above me) I've got a few perl programming books at work here but none of them really explain the @argv use very well.

Do I need to specify a different ARGV for each parameter? and how do I specify it in the line for the shell script?

3 variables to pass into it: $today, $yesterday, $nsrnum
The line calling the shell script: system("diffcheck");
Oct 11 '07 #6
KevinADC
4,059 Expert 2GB
You can try this:

system("diffcheck @ARGV");

that will pass the arguments you passed into your perl script to the shell command. Assumes you have not done anything destructive to @ARGV previously, like:

$argv = shift @ARGV;
Oct 12 '07 #7
I haven't used the ARGV anywhere else, so that should be ok.

I modified that line as suggested. It errors with diff: input file log_err_nsr11.: No such file or directory

The line in my shell script is
diff log_err_nsr11.$yesterday log_err_nsr11.$today > nsr11.diffnew
The variables I defined back in the perl script are the $yesterday and $today. It doesn't look like either the variables are getting passed into it or that I'm using them correctly in the diff command.



You can try this:

system("diffcheck @ARGV");

that will pass the arguments you passed into your perl script to the shell command. Assumes you have not done anything destructive to @ARGV previously, like:

$argv = shift @ARGV;
Oct 12 '07 #8
KevinADC
4,059 Expert 2GB
going to have to see some code. It looks like you are passing literal strings instead of scalar variables.
Oct 12 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: google_nospam | last post by:
Thanks in advance for any help. I'm looking for a way to pass data from php to perl. Basically, I want to take some dynamic data from a database, mixed with user input, then reformat it to make a...
1
by: Romuald Favre | last post by:
Hi there, I just installed Perl (v. 5.6.1. built for MSWin32 from ActiveState) on a new server Windows 2000. Amazingly the passing of arguments doesn't work ! I saved the following code in a...
1
by: Joe | last post by:
I am trying to write a Perlscript to be used with some HTML pages. Here is how it works: 1.. The first HTML page has a form which requests for user input. Then it passes the QUERY_STRING...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
by: asearle | last post by:
Hi everyone, I have a perl script that opens an Access mdb thus: system("C:\\Documents\ and\ Settings\\asearle\\My\ Documents\\iwh_dev\\MyAccessDB.mdb"); This works absolutely fine and,...
4
pawanrpandey
by: pawanrpandey | last post by:
How to pass parameter to a perl file (say myperl.pl) from a shell file (say work.sh ) ? and how to get that parameter in perl file ? { is using my $var = @_ }. Thanks, Pawan Kumar
0
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
3
by: ajaymohank | last post by:
hello everyone..... i am ajay and i am new to php. in my project i have an option to invoke a bat file by passing parrameters and to diplay the result. i tried this code but my page got hung or...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.