Rescheduling perl script using at command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rescheduling perl script using at command
# 1  
Old 09-03-2008
Question Rescheduling perl script using at command

Hi,

I have a perl script which accepts a file as input and ftp the file to a particular sever.I scehduled this script at a specific time using crontab.Everything seeems fine if the input file is available under the path.

Now assume due to some reasons the input file is not avaialble by the time the script is scheduled.So obviously the script will fail.

My requirement is, if the input file is not available then reschedule the script after 30 minutes.I tried to implement this logic using 'at' command by including the below statement in the script :

`at now + 30 minutes -f /home/dileepp/scripts/ftp_file.pl 1> /home/dileepp/logs/ftp_file.log 2> /home/dileepp/logs/ftp_file.log`

As i expected the script is rescheduled after 30 minutes,but by the time it is running, the script is parsed or interpreted using 'sh' and not with 'perl'. The shebang line #!/usr/bin/perl is already there in the script.I don't know why it is not picking up the shebang.The error is like this:

sh: line 35: use: command not found
sh: line 36: use: command not found

(throwing error at the 'use' line which is used to include module in perl, and the error is running long in all the perl specific commands)

Can anybody suggests how to make invoke this rescheduling with the perl intrepreter.I checked the man pages of 'at', but no info regarding this.Environment details are as below:

Perl version: 5.8.3
OS: Linux Ubuntu 2.6.15 i686
at version 3.1.9


Your help is appreciated!


With Regards
Dileep Pattayath
# 2  
Old 09-03-2008
The -f flag to 'at' is to specify a list of commands to be run, you're passing your perl script as if it should be executed in shell, line by line.
You want to provide the perl script itself as the command to execute.

[edit] To pass it on the commandline, echo the job into at and leave out the -f flag:
Code:
echo '/home/dileepp/scripts/ftp_file.pl 1> /home/dileepp/logs/ftp_file.log 2> /home/dileepp/logs/ftp_file.log' | at now + 30 minutes

Note that the 'now + 30 minutes' thing doesn't work on my version of at but you still should be ok with this syntax

Last edited by Smiling Dragon; 09-03-2008 at 11:02 PM..
# 3  
Old 09-03-2008
If it were me doing this script though, I'd probably have it go to sleep for 1800 seconds instead of using at like this, but I suspect it's just a matter of preferance Smilie
# 4  
Old 09-03-2008
Java

Quote:
Originally Posted by Smiling Dragon
If it were me doing this script though, I'd probably have it go to sleep for 1800 seconds instead of using at like this, but I suspect it's just a matter of preferance Smilie
fine.But my question is if i go with your way of letting the script sleep for 1800 seconds, the entire code remains in memory for 30 minutes,right?
But if i reschedule it the memory will be free for 30 minutes.

Since the server is supposed to run a lot of cron jobs may be simultaneously,is better to think from memory perspective.

Please correct me if am wrong,because am not an expert in this!

With Regards
Dileep Pattayath
# 5  
Old 09-03-2008
Java

Quote:
Originally Posted by Smiling Dragon
The -f flag to 'at' is to specify a list of commands to be run, you're passing your perl script as if it should be executed in shell, line by line.
You want to provide the perl script itself as the command to execute.

[edit] To pass it on the commandline, echo the job into at and leave out the -f flag:
Code:
echo '/home/dileepp/scripts/ftp_file.pl 1> /home/dileepp/logs/ftp_file.log 2> /home/dileepp/logs/ftp_file.log' | at now + 30 minutes

Note that the 'now + 30 minutes' thing doesn't work on my version of at but you still should be ok with this syntax
It's working fine.Thanks Smiling Dragon
# 6  
Old 09-04-2008
Quote:
Originally Posted by DILEEP410
fine.But my question is if i go with your way of letting the script sleep for 1800 seconds, the entire code remains in memory for 30 minutes,right?
But if i reschedule it the memory will be free for 30 minutes.

Since the server is supposed to run a lot of cron jobs may be simultaneously,is better to think from memory perspective.

Please correct me if am wrong,because am not an expert in this!
It's an interesting and valid point, as it's an interpreted script, you'd have the perl engine + any variables etc declared sitting about in memory wheras an 'at' invocation would clear out and leave the memory free until it's needed. I'm of the same school of thought that if we don't need to use RAM, we shouldn't.

But, there are some things to consider:
  • Your average perl binary is pretty small as far as memory footprints go
  • Modern unix systems typically don't have the kind of memory issues we used to have, physical chip ram is still precious but swap space on disk is usually rather copious.
  • CPU time is still precious, to start a new perl interpreter up is considerably more expensive on CPU than just running a sleep (to all intents and purposes, 0% cpu used) for 30 mins.
  • The operational risk _could_ be greater using 'at', this really depends on how the job works though. If you run this thing and it's waiting on some condition to complete before it carries on, could someone make the mistake of seeing it's finished running and thinking that means it's done? They might either run it again (resulting in two 'at' jobs scheduled) or assume it's fully complete.
Smilie
# 7  
Old 09-04-2008
MySQL

Quote:
Originally Posted by Smiling Dragon
It's an interesting and valid point, as it's an interpreted script, you'd have the perl engine + any variables etc declared sitting about in memory wheras an 'at' invocation would clear out and leave the memory free until it's needed. I'm of the same school of thought that if we don't need to use RAM, we shouldn't.

But, there are some things to consider:
  • Your average perl binary is pretty small as far as memory footprints go
  • Modern unix systems typically don't have the kind of memory issues we used to have, physical chip ram is still precious but swap space on disk is usually rather copious.
  • CPU time is still precious, to start a new perl interpreter up is considerably more expensive on CPU than just running a sleep (to all intents and purposes, 0% cpu used) for 30 mins.
  • The operational risk _could_ be greater using 'at', this really depends on how the job works though. If you run this thing and it's waiting on some condition to complete before it carries on, could someone make the mistake of seeing it's finished running and thinking that means it's done? They might either run it again (resulting in two 'at' jobs scheduled) or assume it's fully complete.
Smilie
Excellent.What you have explained is all perfectly correct and acceptable.
But in my case,am doing this operation in a development server(and is a temporary operation too).
This development server got a very little RAM and some cronjobs will take around 4-5 hrs to complete execution,but not doing big tasks.So issues with RAM is an important concern for me.
And two 'at' command execution is a possibility and the pass-through for this is already implemented in my program.The conditional block which holds this 'at' command execution statement will fire only if the program is invoked at a particular time,ie 23:45 for eg.

So after the first scheduling time in crontab (23:45),this conditional block will never fire the next time when it is executed with 'at' or manually.

Anyway, putting the ideas and suggestions like this is great because sometimes programmers never look into these areas,but only from a functional perspective.

Good and thanks a lot for a nice discussion.

With Regards
Dileep Pattayath
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using UNIX command in perl script.

I wish to know if there is any limitation in using unix commands in perl script or it is just we should avoid using them in our perl script. For e.g Below is the command to get the recent file in a dir.: $lcsvFile = `cd "$l_inputfilepath";ls -1t *.CSV|tail -1` Is there any harm in coding... (1 Reply)
Discussion started by: Devesh5683
1 Replies

2. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

3. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

4. Shell Programming and Scripting

Send "perl -e '...' " command through SSH, from a perl script

Hey guys I am trying to send a perl -e command to a number of systems using SSH. The command should retrieve some information for me. The problem is, the remote shell tries to interpolate my variables and doesn't get it should take the command literally and just execute it. Below the code.... (2 Replies)
Discussion started by: clrg
2 Replies

5. Shell Programming and Scripting

Crontab Rescheduling

Hi, I want to weekly schedule a script execution (using crontab) but only if the system load is low. My question is: If the script does not be executed ( because of high load ) how can I re-schedule the cronjob to run after some minutes? I want the re-scheduling to be executed until the final... (4 Replies)
Discussion started by: tdakanalis
4 Replies

6. UNIX for Dummies Questions & Answers

Crontab Rescheduling

Hi, I want to weekly schedule a script execution (using crontab) but only if the system load is low. My question is: If the script does not be executed ( because of high load ) how can I re-schedule the cronjob to run after some minutes? I want the re-scheduling to be executed until the final... (1 Reply)
Discussion started by: tdakanalis
1 Replies

7. UNIX for Advanced & Expert Users

Crontab Rescheduling

Hi, I want to weekly schedule a script execution (using crontab) but only if the system load is low. My question is: If the script does not be executed ( because of high load ) how can I re-schedule the cronjob to run after some minutes? I want the re-scheduling to be executed until the final... (1 Reply)
Discussion started by: tdakanalis
1 Replies

8. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies

9. Shell Programming and Scripting

get command alias name in perl script?

hi all, In my perl script, I need to know the command alias name to make my program flexible. I tried many methods like system("alias cmd"), `alias cmd`, use shell qw,etc. But no one could recognize the built in command alias. If I use `which cmd`, it would look for the command based on... (4 Replies)
Discussion started by: ktmchen
4 Replies

10. UNIX for Dummies Questions & Answers

how can call perl script as command?

Hello say i have written some perl scripts , now i like to call them in my unix shell as unix command like "more" , "ls" , "grep" so that my say perl script called "foo.pl" will be called from every where as "foo" or "foo arg1 arg2"? Thanks (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question