Results 1 to 2 of 2

Thread: Batch Script not working correctly via Crontab

  1. #1
    Join Date
    May 2005
    Location
    Milton Keynes, UK
    Beans
    58
    Distro
    Ubuntu 13.04 Raring Ringtail

    Batch Script not working correctly via Crontab

    Hello everyone!

    EDIT: Just tried scheduling the script again just now and closed my session and it worked successfully but its not writing to the log file. This morning the files failed to upload for whatever reason but as it hadn't captured to the log I was unsure of what had happened. The problem appears more to be the &> not piping contents to the log file!

    EDIT 2: Two steps forward, one step back. Changed the crontab to read "/home/fasc/work/stuff/st_transfer/transfer.sh >csvtransfer.txt 2>&1" which now correctly outputs what I want to a text file .... just now the FTP part isn't uploading. Pretty sure this original post is now resolved.

    I've created a batch script that wget's 4 files from a server then uploads them to an FTP server before deleting the saved files locally. If I run this script on its own (included below) it works a treat and if I schedule it via crontab it works great. However, if I then try to capture the output to a log file it works when I do it manually but when I schedule the task via Crontab it doesn't appear to run (no contents saved in the log file).

    Code:
    #!/bin/bash
    
    vf_details="file1_"`eval date +%Y%m%d -d "yesterday"`".csv"
    vf_totals="file2_"`eval date +%Y%m%d -d "yesterday"`".csv"
    vf_bet="file3_"`eval date +%Y%m%d -d "yesterday"`".csv"
    vf_deposit="file4_"`eval date +%Y%m%d -d "yesterday"`".csv"
    
    echo -e "https://webaddress/$vf_details\nhttps://webaddress/$vf_totals\nhttps://webaddress/$vf_bet\nhttps://webaddress/$vf_deposit" >> toget.csv
    
    wget --user=theusername --password='thepassword' -i toget.csv
    
    curl -u 2ndusername:2ndpassword -T "{$vf_details,$vf_totals,$vf_bet,$vf_deposit}" ftp://888.888.888.888
    
    rm *.csv
    And my crontab is as follows;

    Code:
    15 07 * * * /home/fasc/work/stuff/st_transfer/transfer.sh &> /home/fasc/work/stuff/st_transfer/csv_transfer.log
    30 07 * * * echo "Heres the completed log file." | mutt -a "/home/fasc/work/stuff/st_transfer/csv_transfer.log" -s "CSV Transfer" -- me@myaddress.com
    Really scratching my head over this one, I can't understand how it works happily when I run it manually but as soon as I schedule the same command it fails to run? Any help given would be greatly appreciated, thank you!
    Last edited by Fascination; August 3rd, 2013 at 12:31 PM. Reason: Was using the incorrect switch to output.
    I will plunge you into a nightmare world from which there is no awakening. In a lol way.

  2. #2
    Join Date
    Sep 2007
    Location
    Oklahoma, USA
    Beans
    2,378
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: Batch Script not working correctly via Crontab

    Most cron jobs run as root, not as your logged-in user; if this is what is happening for you, then your four $vf* variables in the script need full pathspecs, not just the basic filenames, for it to work.

    However it's possible to have cron jobs run as specific users rather than as root. We need more details about exactly how you are doing the scheduling to tell which is the case here.
    --
    Jim Kyle in Oklahoma, USA
    Linux Counter #259718
    Howto mark thread: https://wiki.ubuntu.com/UnansweredPo.../SolvedThreads

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •