Unix command in Perl

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix command in Perl
# 1  
Old 11-24-2007
Unix command in Perl


I have a perl script. It needs to open a file but the file that it will open will depend on the result of a unix command "tail -1". How can I do that in perl, to open a file which is the results from a unix command? Thanks in advance! Hope you can help me.
# 2  
Old 11-24-2007
this sample should help you !

#! /opt/third-party/bin/perl

$a=`ls | tail -1`;

print "file:$a";

exit 0

# 3  
Old 11-25-2007
Unix command in Perl

Hi Matrixmadhan,

It's you again! Thanks a lot for always taking time to reply on my posts. I was able to do it now but I will also try to do the command that you've recommended. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] UNIX command in PERL

I tried to use this command in PERL code. when I run this on shell , it's working fine. grep -v "^#" /oratab | awk -F: '$1 == "'$server'" {print $2}' inside PERL $ohome = `grep -v "^#" /oratab | awk -F: '$1 == "'$server'" {print $2}'` ; but, it's not returning anything back ... what... (0 Replies)
Discussion started by: talashil
0 Replies

2. Shell Programming and Scripting

Using UNIX command in perl script.

I wish to know if there is any limitation in using unix commands in perl script or it is just we should avoid using them in our perl script. For e.g Below is the command to get the recent file in a dir.: $lcsvFile = `cd "$l_inputfilepath";ls -1t *.CSV|tail -1` Is there any harm in coding... (1 Reply)
Discussion started by: Devesh5683
1 Replies

3. UNIX for Dummies Questions & Answers

PERL/UNIX - SVN check in command

I am working in perl. I need to do some svn check in from my server. I need to install svn in my server. I have the package "svn" in my server path How can I install that in my server. I tried , but this doesnt work. Can you please help with the command to be used. Thanks in... (0 Replies)
Discussion started by: irudayaraj
0 Replies

4. Shell Programming and Scripting

Cannot execute Unix command in a simple perl script

Am trying to lean perl scripting in Unix OS to automate my tasks. Please find the below perl script i have tried #!/usr/bin/perl -w print "Please Enter the VG name to be checked:"; $A = <>; print "Please Enter the free size to be checked in GB:"; $B = <>; $vgcheck = `vgdisplay... (7 Replies)
Discussion started by: jayachandran87
7 Replies

5. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

6. Shell Programming and Scripting

How do I launch a command on an existing terminal in unix using PERL

Hello, I have a PERL-TK based GUI from which I want to launch a command on an existing UNIX terminal (this is also the parent terminal for this perl based gui window). The command I want to launch is interactive (there is no intention to interact with that command from the same PERL gui i.e. no... (2 Replies)
Discussion started by: AnuragJindal
2 Replies

7. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

8. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

9. Shell Programming and Scripting

[PERL] Running unix commands within Perl Scripts

I understand that in order to run basic unix commands I would normally type at the prompt, I would have to use the following format system(ls -l); or exec(ls -l); But when I actually try to use the command, the script fails to compile and keeps telling me there is an error with this line. ... (1 Reply)
Discussion started by: userix
1 Replies

10. Shell Programming and Scripting

E-Mail from command line for UNIX and Perl??

Hi Is there any way to use UNIX and Perl to automate sending e-mail. I got a dynamic changing file that send out to people in my mailing list and want to experinment to see if Perl and UNIX can send it out for me when the content is change. I found a Perl source code but dont really know how to... (4 Replies)
Discussion started by: jy2728
4 Replies
Login or Register to Ask a Question

Featured Tech Videos