By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,799 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,799 IT Pros & Developers. It's quick & easy.

IO redirection

P: 7
Im trying to execute a perl script from a shell script. I have to pass the path of a file in the command line when i execute the perl script (Automate the perl script execution). How do i feed the path to the perl script through the shell script?

Details of the perl script execution:

$perl sample.pl
Enter the filename:

Details of the unsuccessful shell script:
#!bin/sh
/usr/bin/perl /home/name/sample.pl<< "<pathname"

I dont want to hardcode the path. But i tried passing the path of the file using << in the shell. It didnt work. Please help me.
Dec 20 '07 #1
Share this Question
Share on Google+
6 Replies

P: 7
Ppl,

please help me fix this problem. Its kind of urgent..I sat on it for more than 2 days. But im totally lost. Its a pretty dumb problem actually.

Im trying to run a crontask on a remote system. I should execute a shell script at a given time.

For ex: * * * * * bash /Users/name/sample.sh

In the script ive included commands to perform database backup. It works fine. But the problem is that, ive to run a perl script prior to the execute of mysqldump. For some dumb reason, it wouldnt execute.
Details of the file sample.sh:

/usr/bin/perl /Users/name/chumma.pl

If i run this command it should update some tables in my local database. Then i should run mysqldump to import it to a remote database, which works fine.

I dont know why the crontask wouldnt execute. I dont know if there is a problem with the shell syntax or the perl syntax.

Please not that, i SSH into a remote system to run the cronjob..
thelevitator is online now Report Post Edit/Delete Message
Dec 20 '07 #2

sicarie
Expert Mod 2.5K+
P: 4,677
Okay a few things:
Does the perl script run without being in the cronjob? What happens if you cd to /Users/name/ and do a './chumma.pl' ? Also, If you are running a cronjob, you should nto have to remote in to execute this. FYI your example cronjob is not set to run at a specific time. I don't know if that means is runs constantly, or never, but my guess would be never.
Dec 20 '07 #3

P: 7
Hi,

I couldnt get the script to run by giving ./chumma.pl, it executes if i'd give perl chumma.pl. I didnt give the specific time. Please ignore that part. I just want the crontask to execute. So as of now, im just testing it for the next minute.

If i'd try executing using ./chumma.pl it throws the bash error permission denied.

Does it have anything to do with setting the permissions? Is that why it is not executing? But i tried to execute mysqldump command and it does work. Any suggestions??
Dec 20 '07 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
Hi,

I couldnt get the script to run by giving ./chumma.pl, it executes if i'd give perl chumma.pl. I didnt give the specific time. Please ignore that part. I just want the crontask to execute. So as of now, im just testing it for the next minute.

If i'd try executing using ./chumma.pl it throws the bash error permission denied.

Does it have anything to do with setting the permissions? Is that why it is not executing? But i tried to execute mysqldump command and it does work. Any suggestions??
Since you are on a Unix system, and the script won't run when you just give "./chumma.pl", then you need to edit it and ensure that the first line reads:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
The shebang line needs to be the first line in the script and should contain the above (with your path to the perl interpreter of course).


Either way, if you run that shell script (that runs the Perl script), does the Perl script run? If it doesn't then you have an issue there that needs to be resolved before Cron can do its job.

Regards,

Jeff
Dec 21 '07 #5

arne
Expert 100+
P: 315
Im trying to execute a perl script from a shell script. I have to pass the path of a file in the command line when i execute the perl script (Automate the perl script execution). How do i feed the path to the perl script through the shell script?

Details of the perl script execution:

$perl sample.pl
Enter the filename:

Details of the unsuccessful shell script:
#!bin/sh
/usr/bin/perl /home/name/sample.pl<< "<pathname"

I dont want to hardcode the path. But i tried passing the path of the file using << in the shell. It didnt work. Please help me.

If you do not have control over sample.pl yopu could try

Expand|Select|Wrap|Line Numbers
  1. echo "pathname" | /usr/bin/perl /home/name/sample.pl
  2.  
If you have written sample.pl yourself, make the
pathname you want to pass a parameter, so that
you can use

Expand|Select|Wrap|Line Numbers
  1. /usr/bin/perl /home/name/sample.pl pathname
  2.  
in your shell script. For this the sample.pl script
should use the @ARGV array instead of reading
from STDIN.

HTH,
arne
Dec 22 '07 #6

numberwhun
Expert Mod 2.5K+
P: 3,503
This is the SAME question that you asked in your other thread, which still needs an answer(s) from you from my last post to your thread.

I am merging the two threads as we don't need two of the same questions floating around out here.

Regards,

Jeff
Dec 22 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.