Register
It is currently Mon Apr 21, 2014 1:16 am

How to embed perl script in bash script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Jun 09, 2007 8:34 am   

Joined: Mon Jun 04, 2007 11:30 am
Posts: 3
im trying to run a perl script inside a bash script. i've been searching for guides/references and read the Advanced Bash Scripting Guide. But it doesn't clearly explain how to include complex perl commands in a bash script. i've managed to reach upto this point ,

Code:
perl -e 'use File::stat;

use Time::localtime;

$file='/mnt';

$date_string = ctime(stat($file)->mtime);

print "file $file updated at $date_string\n";'



So u see, im trying to search for files created today. But when i try to run the script , i get error "search field incomplete".

Please help.


Top
 Profile  
 PostPosted: Wed Jun 27, 2007 2:04 pm   

Joined: Sat Sep 02, 2006 9:26 pm
Posts: 4
Location: Baltic, South Dakota
jimmy,

is it possible to just use some shell commands to find any files created on today's date in /mnt?

Using `find`: find /mnt -type f -maxdepth 1 -ctime 0 -exec ls -l {} \;

Using `ls`: ls -lr --time=ctime /mnt

That might be an easier way that trying to foogle perl into your bash script (which I haven't ever dabbled with at all). Would that help you out at all?


Top
 Profile WWW  
 PostPosted: Tue Apr 01, 2008 10:59 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
jimmy wrote:
im trying to run a perl script inside a bash script. i've been searching for guides/references and read the Advanced Bash Scripting Guide. But it doesn't clearly explain how to include complex perl commands in a bash script. i've managed to reach upto this point ,

Code:
perl -e 'use File::stat;

use Time::localtime;

$file='/mnt';

$date_string = ctime(stat($file)->mtime);

print "file $file updated at $date_string\n";'



So u see, im trying to search for files created today. But when i try to run the script , i get error "search field incomplete".

Please help.


You forgot to escape your quotation mark. Bash sees this:
Code:
perl -e 'use File::stat;

use Time::localtime;

$file='


Solution:

Code:
$file=\'/mnt\';


OR
Code:
$file="/mnt";


But as iccus said, bash would be better for this particular task :P


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP