[solved] using backticks to call bash from perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [solved] using backticks to call bash from perl
# 1  
Old 04-25-2012
Question [solved] using backticks to call bash from perl

Hi all,

Here is my code:
Code:
my $x = `bash -c \" ls -l filename | awk '{print \$5}'\"`;
print "$x\n";

This will run the first part of the bash script but not the awk command. It therefore gives output of:

Code:
-rw-r--r-- 1 root root 13619200 2012-04-25 08:16 filename

I am actually trying to just extract the filesize, which works correct when the bash command is run in isolation, meaning that perhaps I have a syntax error somewhere inside my backticks...?

Thanks in advance.

Moderator's Comments:
Mod Comment Link: How to use [code] tags


---------- Post updated at 03:01 AM ---------- Previous update was at 02:25 AM ----------

Just to answer my own post as in retrospect, it was a really stupid question.

The answer is, don't use bash, use perl as it is more than capable of carrying out these small functions!

I had previously written the script in bash and i'm in the process of converting the functionality to perl. I guess I got caught up in re-using my previous code from the bash script.

Anyway, I did this in perl instead:
Code:
$fileSize = -s "filename";
print "filesize: $fileSize\n";

It does the job.

Last edited by Scrutinizer; 04-25-2012 at 04:29 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

[Solved] Unable to call a python script from bash

Hi, I am trying to run a python script embedded in bash script. But is throwing me an error. Please help. Script: #!/bin/bash nohup /usr/bin/python /opt/web/http.py & Error: /usr/bin/python: can't open file '/opt/web/http.py': No such file or directory Please help me on this. (6 Replies)
Discussion started by: maddy26615
6 Replies

3. Shell Programming and Scripting

SSH and Backticks [solved]

I have been testing a new script and cannot figure out why my `cat spath` will not execute on the remote machine? sudo ssh -p 22344 -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.1.6 "find `cat spath` -depth" cat: spath: No such file or directory but... (0 Replies)
Discussion started by: metallica1973
0 Replies

4. Shell Programming and Scripting

How to call a bash command from within a perl script?

In a bash script, one can call a perl command in the following manner, where "myperlcommand" is a perl command. perl -e 'myperlcommand(arguments)' perl -e 'print("UUUU"x4)' Now, how can one call a bash command from within a perl script? (Suppose that mybashcommand is a bash... (1 Reply)
Discussion started by: LessNux
1 Replies

5. Red Hat

perl backticks: can't redirect output.

Hi everyone. This is a bit of a perl/linux mixed question. I am trying to redirect STDOUT of chsh by using the following line of perl code. system ("chsh -s /sbin/nologin $testing 1>/dev/null"); This should redirect STDOUT to /dev/null but it won't do that for some odd reason. Any ideas or... (6 Replies)
Discussion started by: austinharris43
6 Replies

6. Shell Programming and Scripting

how to call a bash script using perl

Hi I m new to perl. I m trying to write a perl script that calls a bash script; does anyone have a script already that they can provide or help me out? Thanks a lot. (2 Replies)
Discussion started by: adnan786
2 Replies

7. Shell Programming and Scripting

Howto make ksh skript bash-compatible with backticks

I have the following ksh-script: #!/bin/ksh # Ueberprüfe, ob genau ein Parameter angegeben wurde test "$#" -eq "1" || { echo "USAGE: path_cleanup <PATH_NAME>"; return 1; } # Ueberpruefe, ob awk und nawk installiert sind test -x /bin/nawk || { echo "ERROR: nawk is not installed"; return 1;... (2 Replies)
Discussion started by: doc_symbiosis
2 Replies

8. Shell Programming and Scripting

Perl cgi script to call bash script?

Novice to perl here. I have created a simple web page in perl, with only one submit button. I would like to execute a bash script on the same server when this button is clicked on. Is this possible in perl? I have spent a few days researching this and am unable to find any useful information.... (0 Replies)
Discussion started by: pleonard
0 Replies

9. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

10. Shell Programming and Scripting

Perl - backticks v system in if statements

Can someone explain the difference between backticks and system when evaluated in these if statements: sub getDate { print "start date\n"; if ( system("/bin/date") ) { print "can't get date\n"; exit(2); } print "finish date\n"; } Returns the following: start date Thu... (5 Replies)
Discussion started by: gjkeenan
5 Replies
Login or Register to Ask a Question