Loading ...
Sorry, an error occurred while loading the content.
 

Re: ftp not running through cron ?

Expand Messages
  • vaibhavkh85
    ... running .... ... some ... and ... doing. ... is ... well sorry for the late reply... actually i tried doin it from various ways: 1 ./scriptname ---
    Message 1 of 7 , Jul 2, 2007
      --- In LINUX_Newbies@yahoogroups.com, "Loyal Barber"
      <loyal_barber@...> wrote:
      >
      > --- In LINUX_Newbies@yahoogroups.com, "vaibhavkh85" <vaibhavkh85@>
      > wrote:
      > >
      > > hello
      > >
      > > i tried running ftp command through crontab bt it is not
      running ....
      > > bt the script i wrote for the purpose ( script contains only ftp
      > > command alongwith the ip of server ) is running fine..
      > > am not able to figure out the error
      > >
      > > i also tried to run another cronjob just to check if i was doing
      some
      > > mistake in making cronjob bt this trial cronjob is running fine
      and
      > > hence there seems no problem in created cronjob ....
      > >
      > > please tell me where i may be erring.
      > >
      > > thanx
      > >
      > It would help us a bunch if we had the text of the ftp you are
      doing.
      > I have an ftp job that runs daily out of cron so I would guess it
      is
      > a problem with environment. There is no environment set up for
      > cron jobs like there is when you sign in and run something from the
      > command line. Make sure that you fully path every command.
      >
      > Loyal
      >

      well sorry for the late reply...
      actually i tried doin it from various ways:
      1 ./scriptname ---> scriptname where i wrote ftp command
      2 path of the script to run
      3 direct ftp command
      in all the above i'm giving the same command : ftp ipaddress
      bt not running in cron . if i type ./scriptname directly in terminal
      it runs finely
      one more thing i'm using "cygwin" to run these things
    • Loyal Barber
      ... This won t work as cron has no environment and therefore no current directory. I usually put my scripts in /usr/local/bin. If you were to do the same you
      Message 2 of 7 , Jul 2, 2007
        --- In LINUX_Newbies@yahoogroups.com, "vaibhavkh85" <vaibhavkh85@...>
        wrote:
        >
        > --- In LINUX_Newbies@yahoogroups.com, "Loyal Barber"
        > <loyal_barber@> wrote:
        > >
        > > --- In LINUX_Newbies@yahoogroups.com, "vaibhavkh85" <vaibhavkh85@>
        > > wrote:
        > > >
        > > > hello
        > > >
        > > > i tried running ftp command through crontab bt it is not
        > running ....
        > > > bt the script i wrote for the purpose ( script contains only ftp
        > > > command alongwith the ip of server ) is running fine..
        > > > am not able to figure out the error
        > <snip>
        > > Loyal
        > >
        >
        > well sorry for the late reply...
        > actually i tried doin it from various ways:
        > 1 ./scriptname ---> scriptname where i wrote ftp command

        This won't work as cron has no environment and therefore
        no current directory. I usually put my scripts in
        /usr/local/bin. If you were to do the same you would start
        it in cron as /usr/local/bin/scriptname. That will run
        your script.

        > 2 path of the script to run

        This sounds very much like what I am suggesting. The next
        thing to ask is owner and permissions. I make mine owned
        by root and executable by root only.

        [root@krioni ~]# ll /usr/local/bin/offsite.ksh
        -rwx------ 1 root root 2238 Jun 22 08:21 /usr/local/bin/offsite.ksh

        Then I put the command in root's crontab:

        [root@krioni ~]# crontab -l
        00 22 * * * /usr/local/bin/offsite.ksh

        Finally, I make sure that every command in the script is fully
        pathed:

        cd /var/offsite
        if [ $? != 0 ]
        <snip>
        /usr/bin/zip -m $FILENAME *
        if [ $? != 0 ]
        then
        <snip>
        # now ftp the file
        /usr/kerberos/bin/ftp -i -n -v $FTP_MACHINE <<END0
        user $FTP_USER $FTP_PASSWORD
        binary
        put $FILENAME
        dir $FILENAME
        END0

        Some notes here. "cd" is a built in shell command and
        therefore does not need to be pathed. I use the "if [ $? . . ."
        to check the results of the commands and make sure that
        they have succeeded before moving on. Finally, I have
        set the FTP_MACHINE, FTP_USER, and FTP_PASSWORD variables
        prior to the part of the script I gave you above.

        > 3 direct ftp command

        I don't see how this would ever work. Notice in my example above I
        use "<<END0" to "ENDO" in order to execute my ftp commands.

        > in all the above i'm giving the same command : ftp ipaddress
        > bt not running in cron . if i type ./scriptname directly in terminal
        > it runs finely
        > one more thing i'm using "cygwin" to run these things
        >
        I have never used cygwin, but don't see why that would matter. Others
        may correct my ignorance.

        Loyal


        [Non-text portions of this message have been removed]
      • Jim Reimer
        Loyal Barber wrote: ... I do it almost the same way, except that I put the ftp commands in a seperate file - just personal preference to keep only
        Message 3 of 7 , Jul 2, 2007
          Loyal Barber wrote:

          <snip>

          > cd /var/offsite
          > if [ $? != 0 ]
          > <snip>
          > /usr/bin/zip -m $FILENAME *
          > if [ $? != 0 ]
          > then
          > <snip>
          > # now ftp the file
          > /usr/kerberos/bin/ftp -i -n -v $FTP_MACHINE <<END0
          > user $FTP_USER $FTP_PASSWORD
          > binary
          > put $FILENAME
          > dir $FILENAME
          > END0

          > Some notes here. "cd" is a built in shell command and
          > therefore does not need to be pathed. I use the "if [ $? . . ."
          > to check the results of the commands and make sure that
          > they have succeeded before moving on. Finally, I have
          > set the FTP_MACHINE, FTP_USER, and FTP_PASSWORD variables
          > prior to the part of the script I gave you above.

          >> 3 direct ftp command

          > I don't see how this would ever work. Notice in my example above I
          > use "<<END0" to "ENDO" in order to execute my ftp commands.

          >> in all the above i'm giving the same command : ftp ipaddress
          >> bt not running in cron . if i type ./scriptname directly in terminal
          >> it runs finely
          >> one more thing i'm using "cygwin" to run these things
          >>
          > I have never used cygwin, but don't see why that would matter. Others
          > may correct my ignorance.

          I do it almost the same way, except that I put the ftp commands
          in a seperate file - just personal preference to keep only script
          commands in the script file, with the ftp commands elsewhere.

          ftp < commandfile

          where commandfile would contain the same lines as those between the
          ENDOs above (with or without environment variables).

          --
          -jdr-
        • Cameron Simpson
          ... Actually, cron just has almost no environment. And ALL processes have a working directory. Cron commands will run in your home directory. But don t expect
          Message 4 of 7 , Jul 2, 2007
            On 02Jul2007 19:36, Loyal Barber <loyal_barber@...> wrote:
            | --- In LINUX_Newbies@yahoogroups.com, "vaibhavkh85" <vaibhavkh85@...>:
            | > well sorry for the late reply...
            | > actually i tried doin it from various ways:
            | > 1 ./scriptname ---> scriptname where i wrote ftp command
            |
            | This won't work as cron has no environment and therefore
            | no current directory.

            Actually, cron just has almost no environment. And ALL processes have a
            working directory. Cron commands will run in your home directory.
            But don't expect $PATH to be as it is in your login shell - /etc/profile
            and $HOME/.profile have not been sourced. For example, $HOME/bin won't
            be in cron's $PATH, while it is in most users' $PATHs at the shell
            prompt.

            | I usually put my scripts in
            | /usr/local/bin. If you were to do the same you would start
            | it in cron as /usr/local/bin/scriptname. That will run
            | your script.

            That requires admin rights. If you're running personal stuff, the
            traditional place is the directory $HOME/bin.

            | > 2 path of the script to run
            |
            | This sounds very much like what I am suggesting. The next
            | thing to ask is owner and permissions. I make mine owned
            | by root and executable by root only.
            |
            | [root@krioni ~]# ll /usr/local/bin/offsite.ksh
            | -rwx------ 1 root root 2238 Jun 22 08:21 /usr/local/bin/offsite.ksh
            |
            | Then I put the command in root's crontab:
            |
            | [root@krioni ~]# crontab -l
            | 00 22 * * * /usr/local/bin/offsite.ksh
            |
            | Finally, I make sure that every command in the script is fully
            | pathed:

            I usually just make sure $PATH is sensibly set up. The default cron
            envionment will anyway normally have /bin and /usr/bin, and I usually
            just put any extra settings at the start of the script, eg:

            PATH=$PATH:/some/extra/stuff...
            export PATH

            | cd /var/offsite
            | if [ $? != 0 ]

            "cd" in a script will abort the script if it fails. You don't need to
            test its success or failure.

            | <snip>
            | /usr/bin/zip -m $FILENAME *
            | if [ $? != 0 ]

            A nicer idiom is this:

            if /usr/bin/zip -m $FILENAME *

            Remember that _every_ command should be usable as a condition in
            "if"/"while" and so forth. Certainly any command where you test $?
            afterwards can be used that way unless $? takes on unusual values.

            [...]
            | Some notes here. "cd" is a built in shell command and
            | therefore does not need to be pathed.

            And cannot be. An unfortunate reading of POSIX requires the existence of
            a /bin/cd and some systems have it, but since "cd" _must_ run in the
            current shell a /bin/cd executable is of no practical use.

            | I use the "if [ $? . . ."
            | to check the results of the commands and make sure that
            | they have succeeded before moving on.

            As remarked, just put the commands as the condition of the if.

            Cheers,
            --
            Cameron Simpson <cs@...> DoD#743
            http://www.cskk.ezoshosting.com/cs/

            ...don't permit your spirit to be dampened by pinheaded bottom liners who
            feel the proper work environment is one that resembles a benign prison camp.
            - a Good Times horoscope
          Your message has been successfully submitted and would be delivered to recipients shortly.