Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I am a complete newbie to Linux so bare with me. I've created a script to FTP some files from a RHEL box to a EMC NAS and the ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    1

    FTP script and crontab help needed

    Hello,

    I am a complete newbie to Linux so bare with me. I've created a script to FTP some files from a RHEL box to a EMC NAS and the script works because if I run it script manually it runs fine and transfers the files to the NAS but when I schedule it in the crontab the script runs but it doesn't transfer anything and I pipe the output of the cron job and I see message about 'passive mode refused' and lib: not a plain file, sys: not a plain file, etc...

    I did a vi ~/.netrc which contains the a single line of "machine xxx.xxx.xxx.xxx login ftpuser password xxx"
    My script looks like:
    /usr/bin/ftp -i xxx.xxx.xxx.xxx <<EOF
    cd ftpdir
    lcd localdir
    mput *
    quit
    EOF

    Can someone help tell me what I am doing wrong? I've been banging my head on this for 2 weeks and still can't figure it out. BTW I did the exact same script, .netrc, and crontab setup on CentOS and the crob job runs fine and so those the script so I don't understand why it doesn't work in RHEL.

    Thanks in advance.

    One other note I don't own this RHEL box so I don't use the 'root' account but a separate account was created for me to use and it's suppose to have root level access.

  2. #2
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    It looks like your script is probably being run as root, so you're not ending up in the working directory you expect, nor with the environment you expect. If it runs from the command line as your user. You might try making your cron command look like:
    su - myuser -c "/full/path/to/script"
    where myuser is your user name and /full/path/to/script is the fully qualified pathname/filename of your script.

  3. #3
    Just Joined! jippie's Avatar
    Join Date
    May 2006
    Location
    Eindhoven, the Netherlands
    Posts
    76
    Forget ftp and use (sftp or) scp. Configure sftp/scp to use key authentication, that way you don't need to bother about passwords, passive/active transfers, command-filled here-documents and it is very much more secure.
    Passwords won't travel in the clear accros the network, file integrity is guaranteed, connection to the host is guaranteed and just firing FTP-commands without any intermediate checking of it's output is just ... unwise.

Posting Permissions

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