LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 07-05-2002, 05:22 AM   #1
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 601

Rep: Reputation: 32
Automating an ftp and mail job


Hello!
I have a linux and a solaris pc.
The solaris pc generates a file which can be downloaded by ftp.
So here is what i would like to do:

make a cron on the linux pc that get the file every week and sends it per e-mail to me.

the questions:
1. what do i have to type to get automatic access to the ftp server ?
make an executable file like this ?
ftp xx.xx.xx.xx
username
passwort
filename?
2. how can i mail append a file to a mail ?
mail username & filename or what

thanx
 
Old 07-05-2002, 11:35 AM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Wouldn't it be easier to have the Solaris box mail out the file thru cron instead of having the Linux box have to ftp into it to get it.. ??
 
Old 07-05-2002, 12:14 PM   #3
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,154

Rep: Reputation: 56
the file for auto login using ftp is .netrc in the users homefolder


looks like this...

machine nameofserver1
login username
password userspassword

machine nameofserver2
login username
password userspassword


now you need a script to do what you want

autoftpscript

ftp <<EOF
open nameofserver1
cd pathtofile
bin
mget filename*
bye
EOF

run chmod to set the x bit

chmod 700 autoftpscript


now you want to append it to some file


depends on the file I guess, but you can do something like this

cat filename >> filetoappendto
put the cat command at the end of the script

that's it

run it like this

./autoftpscript




or setup cron job

Last edited by DavidPhillips; 07-05-2002 at 12:25 PM.
 
Old 07-08-2002, 02:11 AM   #4
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 601

Original Poster
Rep: Reputation: 32
does not work

hello!
thanx for your ideas but it does not work!
maybe i habe a problem with the ".netrc" file!
what is needed to use it?
bye
 
Old 07-08-2002, 05:24 AM   #5
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Rep: Reputation: 15
Dizamn!

I am working on something similar and I've gotten past the FTP stage....

What I did was to use a util call ncftp and do an ncftpput from the server where the data is on to the server where the data needs to go. Im my case the server creating the data is a RH7.3 box and the processing box is a Win2K Server with an FTP server and PHP/Perl doing the data parsing and web page generation.

The only hitch I have so far is the context. When the cron job fires it logs into the server and everything but then does not upload the files.

When I fire the script manually it works fine. Therefore I suspect that it's the context in which the cron job runs. Which is kind of wierd cause I scheduled the cronjob in the same user context as I ran the job mannualy.

Definitely need to dig further into that...
 
Old 07-08-2002, 09:13 AM   #6
saavik
Member
 
Registered: Nov 2001
Location: NRW, Germany
Distribution: SLES11 / FC20/ OES / CentOS
Posts: 601

Original Poster
Rep: Reputation: 32
login as root

log into your box as root!
make :

crontab -e -u

and edit the job!
 
Old 07-08-2002, 10:17 AM   #7
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Rep: Reputation: 15
Re: login as root

Quote:
Originally posted by saavik
log into your box as root!
make :

crontab -e -u

and edit the job!
But then that would mean that this job would fire off as root right? I am not opposed to this as a 'brute force' fix but I tend to get leary running too many things in root's context.

The really puzzliing thing is that the script runs fine when I am logged on as the user in question and manually run the script. Since I added the script as a cron job AS that same user then it would follow that it would also work equally well right?

I'll try the root way as a last resort if I can't find any other means to verify why the contexts seem to be conflicting.

Thanks!
 
Old 07-08-2002, 10:51 AM   #8
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,154

Rep: Reputation: 56
The command ftp that I have uses ~/.netrc the .netrc should be in your home folder. It works on mine. look at man ftp

you don't need to be root for the script or the .netrc to work.
 
Old 07-08-2002, 11:57 AM   #9
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,154

Rep: Reputation: 56
unless of course the ftp command has been changed to root only access, or your user has no permission to run the script. I built mine as the user in the users home folder, I guess you could create a global one by putting it in /usr/local/bin. it's up to you and your security scheme
 
Old 07-08-2002, 12:03 PM   #10
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,154

Rep: Reputation: 56
should not be any reason to make a system wide crontab to run something a user wants to run. the crontab is stored according to username and written to the file
/var/spool/cron/username.


did you try to run the cron as the user?

Last edited by DavidPhillips; 07-08-2002 at 12:22 PM.
 
Old 07-08-2002, 10:33 PM   #11
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,154

Rep: Reputation: 56
saavik,

when you say "does not work" what happened? or what didn't work?
 
Old 07-08-2002, 11:26 PM   #12
sewer_monkey
Member
 
Registered: May 2002
Location: Toronto, ON, Canada
Distribution: Ubuntu, Debian, RedHat/CentOS
Posts: 624

Rep: Reputation: 31
Re: Automating an ftp and mail job

Quote:
Originally posted by saavik
Hello!
I have a linux and a solaris pc.
The solaris pc generates a file which can be downloaded by ftp.
So here is what i would like to do:

make a cron on the linux pc that get the file every week and sends it per e-mail to me.

the questions:
1. what do i have to type to get automatic access to the ftp server ?
make an executable file like this ?
ftp xx.xx.xx.xx
username
passwort
filename?
2. how can i mail append a file to a mail ?
mail username & filename or what

thanx
  1. Use wget in a cron job to download the file. For simplicity, make sure wget saves the file with a certain constant filename. The manpage for wget should contain all the info you need to do this.
  2. Use another cron job that emails the file to any e-mail you want. I am sure that you can find a script that does that, or write your own.
 
Old 07-09-2002, 05:22 AM   #13
merana
Member
 
Registered: May 2002
Location: Philly/So. Jersey
Distribution: ESXi CentOS Red-Hat Ubuntuu Solaris Debian
Posts: 80

Rep: Reputation: 15
Quote:
Originally posted by DavidPhillips
should not be any reason to make a system wide crontab to run something a user wants to run. the crontab is stored according to username and written to the file
/var/spool/cron/username.


did you try to run the cron as the user?
Hmmm... Run cron as a user... Well I'd take this to mean that I created the cron job "AS" the user in question... If so, then, yes. I have a user (say "srv" as a username for example. He has rights to a directory in /home/srv that has a subtree that goes from that point. In that subtree you have a dir called /home/srv/app/subapp that has a script called ftplog.

I have a copy of ftplog called ftpchoice that only has one variant in it. Instead of doing some date parsing within the script it takes $1 and uses that instead of the calculated dateval.

This script looks like this:

#!/bin/bash
# HLDS_L Log File Uploader Script
# By Ding
# July 2, 2002
#
# Rev Comments
# A Initial Revision
#
prefix=L
datebod=`eval date +%m%d`
fnwc=*.log
fn=$prefix$datebod$fnwc
echo FTPing logfiles beginning with $fn
cd dod/logs
ncftpput -u srv -p itsnotforreal -a -E some.ip.com . $fn
echo The lion has left!

The crontab entry looks like this:

[srv@freya srv]$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (doftplog installed on Thu Jul 4 08:57:35 2002)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
0 0 * * * /home/srv/app/subapp/ftplog
[srv@freya srv]$

This story get's weirder... I did a forklift upgrade to the server yesterday (which further increased my growing love of linux BTW!) I ripped out the old AMD Thunderbird 800MHz Proc and Mobo that was in it and replaced it with an AMD 2000XP on an MSI745 Ultra MB. The old Mobo had an ISA SB AWE64 that was removed as the new MOBO came with onboard sound. I am also using a MAXTOR PCI EIDE card as the primary controller. I had this on the old board and kept it on the new board to keep from having to play games with the boot loader and drive geometry. Oh, and it went from 384MB of older PC2100 SDRAM to 512MB PC2300 DDR as well!

So when I rebooted after the changes the server came right back up and KUDZU removed the SB AWE and other MOBO specific elements like the VIA USB and replaced it with the correct componets (GAWD! PnP worked right off! Like I said getting to love Linux more and more!) Logged into the user as srv and started the screened session of the application then logged off.

That night when the cron job was supposed to run I got an error instead that it could not find:

/home/srv/app/subapp/ftplog

I am going to check the crontab again. I swear right and left that this was running before the upgrade AND the only error I was getting was that it could not find any files that matched the file specification in the ftolog script... BUT the script was being fired at the right time!

VERY confusing!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to avoid mail from at scheduled job? bomix Linux - Software 3 06-30-2005 06:22 PM
Trouble when automating ftp with shell script hari_s_82 Linux - Newbie 2 09-23-2004 02:17 AM
need only cron job mail on my mail id manojthakkar Linux - Newbie 0 12-20-2003 05:41 AM
automating a job to occur every 60 seconds Tigger Linux - General 1 05-28-2003 11:40 PM
FTP Script (Automating) noodle123 Linux - General 2 10-16-2002 08:17 AM


All times are GMT -5. The time now is 11:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration