|
Home > Archive > Unix administration > January 2006 > Weird Script behavior
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Weird Script behavior
|
|
| amerar@iwc.net 2006-01-13, 10:41 pm |
|
Hi All,
We have a backup script that runs, backups up some files, and then
FTP's them to a remote server.
The script runs from beginning to end. No errors. However, when it
hits the FTP step, it simply does not FTP the files.
However, if I run the script manually, it FTP's the files just fine.
I run the script as root, which it also does from the cron. Anyone
have any ideas?
Here is a snippit of the FTP step:
ftp -nv 192.168.1.100 <<_HERE_
user user password
cd $ftp_path
ascii
prompt
mdel *
$( for file in *.sql ; do
print "put $file"
done )
bin
$( for file in *.zip ; do
print "put $file"
done )
bye
_HERE_
Thanks.
| |
| Kevin Collins 2006-01-13, 10:41 pm |
| In article <1137124051.703810.172480@g47g2000cwa.googlegroups.com>,
amerar@iwc.net wrote:
>
> Hi All,
>
> We have a backup script that runs, backups up some files, and then
> FTP's them to a remote server.
>
> The script runs from beginning to end. No errors. However, when it
> hits the FTP step, it simply does not FTP the files.
>
> However, if I run the script manually, it FTP's the files just fine.
>
> I run the script as root, which it also does from the cron. Anyone
> have any ideas?
>
> Here is a snippit of the FTP step:
>
> ftp -nv 192.168.1.100 <<_HERE_
> user user password
> cd $ftp_path
> ascii
> prompt
> mdel *
> $( for file in *.sql ; do
> print "put $file"
> done )
> bin
> $( for file in *.zip ; do
> print "put $file"
> done )
> bye
> _HERE_
>
Usually, scripts that work from command line but not cron fail due to some
difference in the user environment. Since you don't mention which shell you
use, which shell the script uses or which OS you are using, you aren't going to
get a lot of help...
Cron usually executes commands with /bin/sh, so if your script has no shebang
line, it will execute with /bin/sh, which may not be the same behavior from the
command line. In addition, cron's PATH variable is typically much smaller than
your interactive shell's.
Kevin
--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, PERL and CGI scripting
http://www.unix-guy.com
| |
| Doug Freyburger 2006-01-13, 10:41 pm |
| Kevin Collins wrote:
> amerar@iwc.net wrote:
>
>
>
....[vbcol=seagreen]
....[vbcol=seagreen]
>
> Usually, scripts that work from command line but not cron fail due to some
> difference in the user environment.
And most often because of starting directories. Cron starts
jobs in your home dirctory, but that doesn't seem to be the
issue this time.
> Cron usually executes commands with /bin/sh, so if your script has no shebang
> line, it will execute with /bin/sh, which may not be the same behavior from the
> command line.
And so I trimmed the snippet down to the bits that will only
work in KSH. In Bourne that would use backticks but I
don't know if you can do a whole loop inside a backtick
expression in Bourne the way you can in Korn. Might
need to shuffle those parts up and stitch together the input
not use a here-doc.
| |
| amerar@iwc.net 2006-01-13, 10:41 pm |
|
Sorry, I should have mentioned it.....this is being done in KSH.......
| |
| Chris F.A. Johnson 2006-01-13, 10:41 pm |
| On 2006-01-14, amerar@iwc.net wrote:
>
> Sorry, I should have mentioned it.....this is being done in KSH.......
What is? Please read: <http://cfaj.freeshell.org/google>.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Logan Shaw 2006-01-24, 2:49 am |
| amerar@iwc.net wrote:
> The script runs from beginning to end. No errors. However, when it
> hits the FTP step, it simply does not FTP the files.
>
> However, if I run the script manually, it FTP's the files just fine.
>
> I run the script as root, which it also does from the cron. Anyone
> have any ideas?
>
> Here is a snippit of the FTP step:
>
> ftp -nv 192.168.1.100 <<_HERE_
> user user password
> cd $ftp_path
> ascii
> prompt
> mdel *
> $( for file in *.sql ; do
> print "put $file"
> done )
> bin
> $( for file in *.zip ; do
> print "put $file"
> done )
> bye
> _HERE_
I wrote a very similar script, and FTPs things just fine, whether
I run it through cron or interactively.
I would try replacing "ftp" with "cat", run the script from cron,
and see if you are getting the ftp commands you expect that you
should be getting.
By the way, you should be able to do "mput *.sql" and "mput *.zip"
instead of those for loops you're doing.
- Logan
| |
| Barry Margolin 2006-01-24, 2:49 am |
| In article <1137124051.703810.172480@g47g2000cwa.googlegroups.com>,
amerar@iwc.net wrote:
> Hi All,
>
> We have a backup script that runs, backups up some files, and then
> FTP's them to a remote server.
>
> The script runs from beginning to end. No errors. However, when it
> hits the FTP step, it simply does not FTP the files.
>
> However, if I run the script manually, it FTP's the files just fine.
>
> I run the script as root, which it also does from the cron. Anyone
> have any ideas?
Could there be different versions of "ftp" on your system? Since cron
jobs don't run .profile, they don't have the same $PATH, so it might be
running a different version than when you run the script manually.
>
> Here is a snippit of the FTP step:
>
> ftp -nv 192.168.1.100 <<_HERE_
> user user password
> cd $ftp_path
> ascii
> prompt
> mdel *
> $( for file in *.sql ; do
> print "put $file"
> done )
> bin
> $( for file in *.zip ; do
> print "put $file"
> done )
> bye
> _HERE_
>
>
> Thanks.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|