Error executing shell command from a perl script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error executing shell command from a perl script
# 1  
Old 02-19-2008
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.

# 2  
Old 02-19-2008
try using :
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 11:06 AM..
# 3  
Old 02-19-2008
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`;
# 4  
Old 02-19-2008
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

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;

# 5  
Old 03-30-2009
System command in perl

i too have some problem with command source..

system("source set_file");
if ( $? == -1 )
print "command failed: $!\n";
# printf "command exited with value %d", $? >> 8;
print "set\n " ;


After running this. Im getting following error:
command failed: No such file or directory

it giving error although the file exists.

can somebody help me how to operate source command using system function in perl.
# 6  
Old 03-30-2009
source isn't a system command, but a shell-internal, telling it to read the given script in the current shells context. To check this, at the command prompt enter
$ which source
$ type source
$ type .

If you get anything but "is a shell builtin" or "not found", I'd be very surprised.

Try running it as
system("/usr/bin/ksh set_file");

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while executing the shell script

Hi Gurus, The following script fails with the error 'command not found' while trying to execute. As the error indicates, the script fails at ROW#30 where the EOF is defined for SQL statement. It appears that the script is trying execute the lines in the SQL output written to ta spool file.... (7 Replies)
Discussion started by: svajhala
7 Replies

2. Shell Programming and Scripting

Executing 'exit' command from shell script

Hi, I am writing shell script to automate few use cases for CLI interface. We have CLI interface which has bunch of commands. I am trying to execute one of the commands 'exit' as part of automation to exit from CLI object (not from shell script) in my shell script. My intension is to execute... (4 Replies)
Discussion started by: Mahesh Desai
4 Replies

3. Shell Programming and Scripting

Executing perl script in Linux gives :Exec format error. Wrong Architecture

i have perl script that used to be working great , once i edit it in windows and convert it to UTF-8 and then via FTP return it . also did: chmod +x and then when i try to run it : ./ im getting this error: ./ Exec format error. Wrong Architecture.... (4 Replies)
Discussion started by: umen
4 Replies

4. UNIX for Dummies Questions & Answers

Cron shell script not executing diskutil command

I'm trying to learn how to use cron for repetative tasks. I have an external disk that needs to be unmounted and remounted every hour due to some problems that a backup utility (specifically, TimeMachine) is having repeatedly accessing the device. I've created a shell script that will find the... (3 Replies)
Discussion started by: illuminate
3 Replies

5. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@ The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

6. Shell Programming and Scripting

Error in executing Perl script

Hello All I am facing an issue The unix script is running fine in unix environment which uses ssh connection but when I try to run the same in informatica environment (same server where I was running the unix script manually successfully) its showing the below error command-line line 0:... (11 Replies)
Discussion started by: Pratik4891
11 Replies

7. Programming

Executing a awk command inside perl script --

Hello experts I want to execute a awk command, which reads from txt files and sums the numbers from the first column for those listed only inside a <init> block -- The awk command is like awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum} So, I want to execute... (2 Replies)
Discussion started by: Alkass
2 Replies

8. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

9. Shell Programming and Scripting

Problem Executing Firmware Command using Shell Script

Guys, I have a script that should change one of the configuration Parameter in a http accelerator, this config change which will halt http traffic into device. So I have designed a script which should do these changes. But after executing this script, found that one of the input variable is not... (8 Replies)
Discussion started by: raghunsi
8 Replies

10. Shell Programming and Scripting

Error executing shell script in Linux

Hi, I have following shell script code : ------------------------------------------------------------------ #!/bin/bash SCRIPTS_DIR="/scriptsDir1" # tables login/password APIL_USER="uname/pswd" I2_USER="uname/pswd" # Database DB="db1" cd "$SCRIPTS_DIR/scriptsDir2" sqlplus... (2 Replies)
Discussion started by: Chaitrali
2 Replies
Login or Register to Ask a Question