The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl Script Error with find command MKNENI Shell Programming and Scripting 4 03-26-2008 09:02 AM
mv command is giving error in shell script gammit Shell Programming and Scripting 5 12-13-2007 12:56 AM
Error message while executing the shell script ajayyaduwanshi Shell Programming and Scripting 4 10-25-2007 04:12 AM
perl - why is the shell script executed before the print command? mjays Shell Programming and Scripting 3 09-21-2007 02:49 AM
perl command help in shell script venky_2_2000 Shell Programming and Scripting 2 09-06-2005 02:20 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-19-2008
Registered User
 

Join Date: May 2006
Posts: 6
Error executing shell command from a perl script

Hi Gurus,
I've a find command that gets the list of files from a source directory where the extension is not html, xml, jsp, shtml or htaccess. The below find command runs fine from the command prompt or in a shell script. I need to eventually run it in a PERL script and am getting the following error when run from perl script.

`find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print`;

sh: syntax error at line 1 : `(' unexpected

Running out of fuel and would appreciate any help or suggestions to make this work.

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 02-19-2008
sysgate's Avatar
Unix based
 

Join Date: Nov 2006
Location: /root
Posts: 1,200
try using :
Code:
system ("find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print");
The error you got is most probably related to un-escaped symbols, missing quotes, etc.
Or if you want to use the backthicks, put "" around them.

Last edited by sysgate; 02-19-2008 at 07:06 AM.
Reply With Quote
  #3  
Old 02-19-2008
Registered User
 

Join Date: May 2006
Posts: 6
Thanks for your response. I tried using system ("find <Source-dir-path> ! \( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \) -type f -print"); but that reported the same syntax error. I noticed that perl was eliminating the '\', so to get over the issue I used '\\' like indicated below and it worked like charm
`find <Source-dir-path> ! \\( -name '*.html' -o -name '*.xml' -o -name '*.jsp' -o -name '*.shtml' -o -name '*.htaccess' \\) -type f -print`;
Reply With Quote
  #4  
Old 02-19-2008
Registered User
 

Join Date: Jan 2008
Posts: 327
Perl has a module used for this purpose File::Find which should be more efficient than shelling out to the find command. It is also easy enough to code if you don't need to search sub directories

Code:
opendir (DIR,'path/to/folder') or die "$!";
my @files = grep {-f "path/to/folfer/$_" && !/\.html$|\.xml$|\.jsp$|\.shtml$|\.htaccess$/} readdir DIR;
close DIR;
print "$_\n" for @files;
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0