Automating Perl Script

Posted on 2011-10-04
Last Modified: 2012-06-27

I want to automate a  Perl script to run daily. Right now I am executing it from the command line as

uniserver:/usr/qa/Scripts/files> ./  filename

where is the script and the filename is the file it has to process.(like input file)

but when automating how can I call the script with the filename.

I tried it wrap it up in another script as:


do '/usr/qa/Scripts/files> ./  filename'      

and call the above script in Cron  but it is not working.

Question by:new_perl_user
    LVL 5

    Expert Comment

    why cant u hard code the variable inside the script..

    instead of $1 ..use this my $filename=filename

    Author Comment


    LVL 23

    Accepted Solution

    If you have a script in 'cron' that depends on a file in a local directory, you can do one of 2 things, either 'cd' to the directory first in your crontab and then "&&" the script you want to run (this is also what you want to do if your script opens a file for output and you want it in the same directory):
    #min hour day.of.month month day.of.week command
    30 3 * * * cd /usr/qa/Scripts/files && ./ filename

    Open in new window

    Or just give the full path to both the script and the filename:
    #min hour day.of.month month day.of.week command
    30 3 * * * /usr/qa/Scripts/files/ /usr/qa/Scripts/files/filename

    Open in new window


    Author Comment


    I tried earlier the second one but it did not work. will try the first option and will update.
    LVL 9

    Expert Comment

    Did the cron job fire? Did the script start?

    If the cron job fired and script started but failed, or script proved unstartable root would get a mail about the problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now