Jump to content

script will execute in bash, but not with cron


Guest eksit
 Share

Recommended Posts

Guest eksit

hello.

 

i am having a problem with my testing of cron.

i have a ftp script called "backupscript" located in /home/eksit/test/backupscript. the file is executable.

 

this is the file:

 

#!/bin/bash

wall A system backup is currently being performed...

ftp -in <<EOF

open 127.0.0.1

user eksit ***

bin

hash

prompt

cd /home/eksit/test2

put testtext

bye

wall A system backup has completed... Files FTP'ed to Backup Server

 

 

 

from su, i do:

 

#crontab -u eksit /home/eksit/eksit

 

so the output of :

 

#contab -l

 

is:

 

# DO NOT EDIT THIS FILE - edit the master and reinstall.

# (/home/eksit/eksit installed on Thu May 4 23:17:48 2006)

# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)

 

19 23 * * * /home/eksit/test/backupscript

 

this script executes nicely manually from a bash prompt. however, it hangs indefinitly when run by cron.

 

any ideas on what i am doing worng?

 

thank you in advance.

Link to comment
Share on other sites

I've found with some jobs that I've had to use the full path to the program command in the script. Eg: /usr/bin/ftp instead of just ftp on it's own. I found my jobs weren't working, and this was why. Although I normally just drop the scripts in /etc/cron.daily instead of setting up crontab.

Link to comment
Share on other sites

Guest eksit

Thank you for your reply.

 

I tried to change the path to /usr/bin/ftp with no result.

 

I see a message that states "You have new mail in /var/spool/mail/eksit".

 

Am I correct in assuming that error output will be mailed here? Please excuse my ignorance, but how do I check this account? I am not familiar at all with sendmail.

 

Also, you stated that you drop your scripts in /cron.daily. Are you able to control when the scripts are executed, if so how?

 

Thanks again for the assistance.

Link to comment
Share on other sites

Am I correct in assuming that error output will be mailed here? Please excuse my ignorance, but how do I check this account? I am not familiar at all with sendmail.

open a terminal and run the command:

mail

for more information on the mail command, as always:

man mail

Link to comment
Share on other sites

Guest eksit

Thank you. I wasn't sure which program to man.

 

I solved my problem. My guess is that cron was not able to ftp to 127.0.0.1. When using a remote ftp site, the scheduled script works perfectly.

 

Here is the script in case anybody wants it:

 

 

 

 

 

#!/bin/bash

#backup script for simple ftp transaction scheduled with cron

#works with iis installation. substitute username as "anonymous" with an email for the pasword for anonymous connections.

#please note that for this example to work, it assumes that the script is located in the same directory as the files to be transferred.

#

#

#

#Broadcast Start of Backup

wall A system backup is currently being performed...

#Mail the Administrator

#mail anybody@anywhere.com -s "FTP Backup Done" -v < system.txt

#FTP the file to the backup directory on the backup server

/usr/bin/ftp -in <<EOF

#ip adress of remote host goes here

open 192.xxx.xxx.xxx

#username and pass go here. i.e., a user named "eksit" with the pass "nobody" would modify the next

#line to read "user eksit nobody"

user username pass

#leave the next three lines alone

bin

hash

prompt

#to switch remote directorys: if you had a directory on the remote machine called #"happy", the line would read "cd happy"

cd happy

#upload file, i.e. for a file called "testtext", the line would read "put testtext"

put testtext

bye

 

 

 

There's alot of comments i put in there for anybody who is learning like i am!

 

Thanks for your time to everyone who replied.

Edited by eksit
Link to comment
Share on other sites

  • 3 weeks later...
Guest eksit

ok.

 

so i've been working on this job again, and i realized that standard ftp will not upload directories.

 

so after 10 hours, much google and about 64 oz of beer, i present to you a new script!

 

-you must have ncftp installed. standard ftp alone will not allow you to do this properly!

 

 

 

 

 

 

#!/bin/bash

 

ncftp -R -u (username) -p (pass) (hostname/ip) / /home/eksit/backup/(directory name)

 

 

 

 

 

add this to cron , and you are a pimp!

 

im not gonna comment this one becuase im too tired.

 

if you need help, email eksit@adelphia.net.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...