#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    42
    Rep Power
    11

    Help with cronjob/shell script


    I have a shell script that I am tring to call from root's crontab. For some reason it is not working. The error seems to be: "Unknown command." The shell script is located in /. Here is the crontab entry.

    59 23 * * * cd /; ./ftp_smarter.c

    I have also tried /bin/sh ../ftp_smarter.c

    Here is the shell script:

    Code:
    #!/bin/sh
    HOST='hostname'
    USER='username'
    PASSWD='password'
    FILE='grab.txt'
    
    cd /home/price
    /usr/bin/pftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    put $FILE
    quit
    END_SCRIPT
    exit 0
  2. #2
  3. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    If you are wanting to execute ftp_smarter.c which is in the root directory then just use /ftp_smarter.c as the command - and make sure it is executable.
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    42
    Rep Power
    11
    OK, I set that as the command but I am still getting the same error. Is there something wrong with my script? I have no problems running it from the cli.
  6. #4
  7. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    You have the same form of quotes around the follwing lines:
    Code:
    HOST='hostname'
    USER='username'
    PASSWD='password'
    FILE='grab.txt'
    What exactly are you trying to do with them? Did you mean to set some of the variables to the return value of a command? If it runs ok from command line then I would suggest that your PATH is not set up correctly in the script.
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    42
    Rep Power
    11
    My script now looks like this:

    Code:
    #!/bin/sh
    PATH=/usr/local/bin:/usr/bin:/bin             
    HOST='hostname'
    USER='username'
    PASSWD='password'
    FILE='grab.txt'
    
    cd /home/price
    pftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASSWD
    put $FILE
    quit
    END_SCRIPT
    exit 0
    but I am still getting the exact same error? Should I try adding it to /etc/crontab to see if it works from there?
  10. #6
  11. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    It should not make much difference where it is (roots crontab or /etc/crontab). Do we know exactly what is casuing the error? Is there anything in roots mail?
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    42
    Rep Power
    11
    The error that I am posting here comes from root mail. I have also checked /var/log/messages .. and etc. but have found nothing that relates to my issue. I am sure that I am doing something wrong because from my experience user error is usually to blame
    I just can't seem to figure out what I am doing wrong. I did try adding it to /etc/crontab just to see what happens and came up with nothing. Thanks very much for your help. If you come up with any more ideas please post them here.
  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    Try adding some echo statements to the script and see if they show up in the logs. That way you may be able to isolate where the problem is.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  16. #9
  17. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    879
    Rep Power
    333
    The use of echo for debugging is a good idea.
    cron is normally, in my experience, a little friendlier with script errors which makes me continue to think it might be the actual crontab entry with the issue.
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    BC, Canada
    Posts
    16
    Rep Power
    0
    Did you ever get this working? If not try this it works great for me (FreeBSD 4.10 and 5.5):

    Code:
    #!/bin/sh
    
    HOST="hostname"
    USERNAME="username"
    PASSWORD="password"
    FILE="filename"
    
    ftp -d -n -v $HOST <<!
    quote user $USERNAME
    quote pass $PASSWORD
    passive on
    prompt off
    progress on
    binary
    put $FILE
    ls
    bye
    !
    This assumes you are using the supplied FreeBSD FTP server and you have the path set correctly in your crontab.

IMN logo majestic logo threadwatch logo seochat tools logo