Weird Script behavior
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Weird Script behavior




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Weird Script behavior  
amerar@iwc.net


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 03:41 AM


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.






[ Post a follow-up to this message ]



    Re: Weird Script behavior  
Kevin Collins


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 03:41 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?
>
> 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 sheban
g
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 th
an
your interactive shell's.

Kevin
--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, PERL and CGI scripting
http://www.unix-guy.com





[ Post a follow-up to this message ]



    Re: Weird Script behavior  
Doug Freyburger


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 03:41 AM

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 sheb
ang
> line, it will execute with /bin/sh, which may not be the same behavior fro
m 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.






[ Post a follow-up to this message ]



    Re: Weird Script behavior  
amerar@iwc.net


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 03:41 AM


Sorry,  I should have mentioned it.....this is being done in KSH.......






[ Post a follow-up to this message ]



    Re: Weird Script behavior  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-14-06 03:41 AM

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





[ Post a follow-up to this message ]



    Re: Weird Script behavior  
Logan Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 07: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





[ Post a follow-up to this message ]



    Re: Weird Script behavior  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-24-06 07: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 ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:23 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register