homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Path and batch in Linux
I'm absolutely lost

 8:09 am on Dec 23, 2008 (gmt 0)

I need to execute every hour a FTP batch file to download the content of a directory in server A in another directory in server B.

I'm working in the online (dedicated) server B so I've set up a cron job in this server but I can't do it run.

The cron task works fine and it executes the job every hour so the problem is the commands file or the command itself. Let's see.

The command I have now as cron job is: var/www/vhosts/mydomain.com/private/netrc.bat

The contents of netcr.bat are:

ftp -p -i
machine ip-here
login loginname-here
password loginpass-here
macdef init
lcd c:\var\www\vhosts\mydomain\httpdocs\tmp\zz\
cd ZZ
mget *
lcd c:\var\www\vhosts\mydomain\httpdocs\tmp\gr\
cd GR
mget *

(Two blank lines above)

And every time the job is done the message I receive is:
/bin/sh: var/www/vhosts/mydomain.com/private/netrc.bat: No such file or directory

... but the file is really there

Should I ask for root permisson and put the file into bin/sh ?
There is any basic syntax error?

[edited by: Lexur at 8:10 am (utc) on Dec. 23, 2008]



 10:25 am on Dec 23, 2008 (gmt 0)

have you tried running ftp from the command line and entering the same commands?

just a wild guess, but i would try this one change:
cd ../GR

(in case GR and ZZ are both subdirectories of the document root)


 10:29 am on Dec 23, 2008 (gmt 0)

just a wild guess, but i would try this one change:

Yup, that will be it. But you should CD to *full* paths in a CRON call script like this - relative paths are not loaded by CRON.

... but the file is really there

Ah yes, but:-

or directory

I always miss warnings like that too first time around.


 10:52 am on Dec 23, 2008 (gmt 0)

relative paths are not loaded by CRON

in this case the path is relative to the home directory of the user that is logged in with the script so it might be ok.
still safer to remove the possible ambiguity by specifying full paths.


 9:31 pm on Dec 23, 2008 (gmt 0)

...running ftp from the command line ...

I will search how to run a command from the command line in a remote/dedicated server to some tests.


 9:53 pm on Dec 23, 2008 (gmt 0)


Now I have putty.exe to run commands from the console.
Call me stupid but I can't understand why, if I type
I receive
-bash: cd..: command not found

Well... now I changed the command to be "cronned" to
and the message I receive is
Permission denied

Growing Pains.

I hope to solve this issue before this year ends.

So... who runs the cronjobs? root? The user?


 12:17 am on Dec 24, 2008 (gmt 0)

Permission problems are just a matter of finding the file that you don't have permission for. You may have some success by logging in as the user that is running the cron, then manually executing the batch file, line at a time.

The problem with your cd commmand is that there's a space between the 'cd' and the '..'. It's not 'cd..', it's 'cd ..'.

Personally I wouldn't be futzing with putty and ftp. I'd look into rsync to get this done. It's what I use for my nightly offsite backups. fast, secure, and can be set up to only move over changed files.


 8:58 am on Dec 24, 2008 (gmt 0)

I think I'm beginning to see the light at the end of the tunnel.

a) Now I have (as cronjob has) permission to execute the file.
b) The cd .. command now runs with the space.

What I receive now is

: unknown option
/var/www/vhosts/mydomain.com/private/netrc.bat: line 2: machine: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 4: password: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 5: macdef: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 6: prompt : command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 7: lcd: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 8: cd: ZZ : No such file or directory
/var/www/vhosts/mydomain.com/private/netrc.bat: line 9: mget: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 10: cdup : command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 11: lcd: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 12: cd: GR : No such file or directory
/var/www/vhosts/mydomain.com/private/netrc.bat: line 13: mget: command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 14: cdup : command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 15: quit : command not found
/var/www/vhosts/mydomain.com/private/netrc.bat: line 16: : command not found

I supose it means the syntax in this batch files is wrong or even it is not a ftp batch file.
Back to search.


 5:07 am on Dec 26, 2008 (gmt 0)

: unknown option
/var/www/vhosts/mydomain.com/private/netrc.bat: line 2: machine: command not found

this looks like your ftp command failed and it is now running all the ftp command input as if they were system commands.
get the "ftp" command working first.

also i've never heard of a "machine" command for ftp.
try using the "open" command or appending the domain or ip address to the ftp command.


 8:32 am on Dec 27, 2008 (gmt 0)

What I have now:

- cronjob works properly and runs the command every hour; I receive an email every time the task is completed
- the command I use now is "bash /var/www/vhosts/mydomain.com/private/ftpbatch.txt"
- this ftpbatch.txt contains:

ftp -n -v re.mote.ser.ver <<-ENDTAG
user me mypassword
lcd /var/www/vhosts/mydomain.com/httpdocs/tmp/zz/
cd ZZ
mget *
mdelete *

...and what's happening now?

That's what I get in the email I receive hourly:

Connected to re.mote.ser.ver (re.mote.ser.ver).
220-Microsoft FTP Service
220 FTP
331 Password required for me.
230-This is a monitored private system. Do not attempt to login unless you are an authorized user.
230 User me logged in.
200 Type set to A.
Local directory now /var/www/vhosts/mydomain.com/httpdocs/tmp/zz
250 CWD command successful.
mget 20081226140045? 227 Entering Passive Mode (re,mote,ser,ver,172,145).

125 Data connection already open; Transfer starting.
WARNING! 24 bare linefeeds received in ASCII mode File may not have transferred correctly.
226 Transfer complete.
mget 20081226141309? mget 20081226141600? mget 20081226141634? mget 20081226141704? mget 20081226141819? mget 20081226142211? mget 20081226154504? mget 20081226160313? mget 20081226160346? mget 20081226204022? mget 20081226204702? mget 20081226211029? mget 20081226211857? mget 20081226213446? mget 20081226214418? mget 20081226220618? mget 20081226222538? mget 20081226224023? mget 20081226233130? mget 20081226233545? mget 20081227021429? 221

From HP ARPA File Transfer Protocol User's Guide:

221 Server is closing command connection
Cause: The server received a QUIT command and is shutting down.

Who's sending a QUIT command?
Why server is closing the command connection?


 1:53 pm on Dec 28, 2008 (gmt 0)

maybe the file globbing in the mget is causing an issue.
try adding a "prompt" command before the mget.


 8:37 am on Dec 29, 2008 (gmt 0)


Thanks Phranque, TrillianJedi and Wheel.

So, if anyone who runs a dedicated server with Linux (RedHat) and Plesk want to make automatic FTP connections hourly between two servers, he must to:

1.- Set up a cronjob with a number between 01 and 59 in the "Minutes" fiel and an asterisk in the other fields
2.- Copy the script (see above) and edit your own parameters : IP, username and password, save it as ftpcommad.txt, i.e., and upload it to your private directory, probably /var/www/vhosts/yourdomain.com/private/ Change its permissions to 755 to avoid ownership isuues.
3.- Write in the cronjob command field "bash var/www.vhosts/yourdomain.com/private/ftpcommad.txt"

I worked for me.

The script itself:

ftp -n -v my.ip.he.re <<-ENDTAG
user myusername mypassword
lcd /var/www/vhosts/mydomain.com/httpdocs/zz/
cd ZZ
mget *
mdelete *
lcd /var/www/vhosts/mydomain.com/private/


 9:43 am on Dec 29, 2008 (gmt 0)

Congrats on getting it working and thanks for sharing the solution.

Now you've got something working I would suggest you look to improve it with Wheel's original suggestion of moving to RSync. It's better because it's secure (it'll run over an encrypted secure shell session) and also it'll only copy over what's needed, e.g. anything that's new or has changed, which makes it a lot quicker.


 3:38 pm on Dec 30, 2008 (gmt 0)

I've previously detailed somewhere around here the complete steps I took to get my rsync working.


 12:04 pm on Dec 31, 2008 (gmt 0)

that would probably be this one:
Backup up your webserver to your home computer. [webmasterworld.com]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved