LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 10-04-2007, 03:50 AM   #1
svar
Member
 
Registered: Jul 2003
Posts: 362

Rep: Reputation: 30
ftp in inittab -.netrc issue


I need a continuous ftp file upload between two computers.
I have a shell script that runs fine, it gets files in /myuser/MYFILES
, reads the user and passwd from /home/myuser/.netrc and does the transfer fine.
The problem arises when I want to robustify this: I want the script
in inittab, so that if there is a problem, say a maintenance shutdown,
the process will be running whenever the machine is up again.
So I put the script in inittab and it does not work. To debug,
I logged in as root and tried /myuser/ftpscript
(which works fine when I log in as myuser)
and I get a user+password prompt, which means it does not see .netrc, since inittab is not running as myuser(and chmod 666 will not do). So I copied .netrc to / as 600, got nowhere and then remembered that the home
of root is /root in modern systems, so I copied it to /root instead (owner root, group sys, mode 600), but I still get the prompt.

Any ideas of what I am doing wrong?
 
Old 10-04-2007, 04:19 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Most likely root cannot use ftp (that's the default in all distros). If you want root to use ftp then edit /etc/ftpusers in server and remove root. Also check if your ftp server software configuration denies root access.
 
Old 10-04-2007, 05:09 AM   #3
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
No, I can ftp to the same ip as root, fine. It even finds the user name and password from .netrc, so I do not have to type in anything
other than ftp destination_ip. It is when I run the script as root that I get the prompt
 
Old 10-04-2007, 05:59 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Perhaps you could post the script here to see why it works as user and not as root.
 
Old 10-04-2007, 06:21 AM   #5
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
#!/bin/sh
cd /myuser/MYFILES
while 1>0
do


for i in 20*.LOADED
do
l=$i
echo "getting length"
l=`expr length $l`
l=`expr $l - 7`
echo " i=$i l= $l "
oldfile1=`expr substr $i 1 $l `
echo "i=$i l= $l oldfile=$oldfile1"
mv $i $oldfile1
done

echo "done with loaded"
#sleep 600
sleep 10
for oldfile in 20*.av
do
chmod 666 $oldfile
rm testx.gz
echo "oldfile = oldfile and $oldfile"
/var/opt/Data/proprietary_program -a -pd -ca -ti -o testx $oldfile
echo "ran proprietary_conversion on $oldfile ">>/myuser/var/DONEALL
/usr/contrib/bin/gzip -q9 testx
echo " gzipped testx "
ftp 172.16.167.5 <<**
echo "opened ftp"
#<<**
cd /home/myuser/MYFILES
echo "cdd to MYFILES"
put /myuser/MYFILES/testx.gz /home/remote_user/MYFILES/$oldfile.gz
echo "put file">>/myuser/var/DONEALL
#quit
bye
**
echo "removing $oldfile"
rm $oldfile
echo "removed $oldfile"
ls -l $oldfile
#fi
done
done
 
Old 10-04-2007, 07:24 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
I was interested for the ftp part of the script
Quote:
ftp 172.16.167.5 <<**
echo "opened ftp"
#<<**
cd /home/myuser/MYFILES
echo "cdd to MYFILES"
put /myuser/MYFILES/testx.gz /home/remote_user/MYFILES/$oldfile.gz
echo "put file">>/myuser/var/DONEALL
#quit
bye
The fact is that this snippet it's not working for me until I remove all the lines that are not ftp commands (i.e. the comments and the echo statements).
Then it works as expected!!! Perhaps you should try just the above snippet to make it work and then add the rest of the commands.
 
Old 10-04-2007, 08:56 AM   #7
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
Got rid of all the echos and comments. Still no luck
 
Old 10-04-2007, 09:08 AM   #8
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
The real issue is that doing
ftp 172.16.167.5

as myuser automaticall connects you to the remote site, no user names and passwords asked

Doing the same as root wants user name and password.
This is what needs to be fixed. Apparently copying .netrc to /root
will not do it.(BTW, the remote machine is linux, this one
is HP-UX, but it should make no difference)
 
Old 10-04-2007, 09:56 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
No, I can ftp to the same ip as root, fine. It even finds the user name and password from .netrc, so I do not have to type in anything
and then
Quote:
The real issue is that doing
ftp 172.16.167.5

as myuser automaticall connects you to the remote site, no user names and passwords asked

Doing the same as root wants user name and password.
I am still thinking that root cannot ftp to the server as it's normal in a default installation. But you can use in root's .netrc the username/password of the user you want, so root runs your scripts and then connects to the ftp server as that user:
Code:
machine  172.16.167.5
login    myuser
password mypassword
 
Old 10-04-2007, 11:06 AM   #10
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
In my experience normal is that you should not ftp TO root. At any rate
the point is that root does not respect the .netrc file, even if
I put in in /root. There should be a way to override this, but I am not sure how it's done and I have been unable to find this
 
Old 10-04-2007, 11:53 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
At any rate
the point is that root does not respect the .netrc file, even if
I put in in /root.
I'm not familiar with HP-UX, but I guess that since a normal user can use .netrc, so can root. Perhaps /root is not root's homedir.
Another thing you can do is to use "su myuser" before invocing ftp in your script.
 
Old 10-10-2007, 02:15 AM   #12
svar
Member
 
Registered: Jul 2003
Posts: 362

Original Poster
Rep: Reputation: 30
Looks like
su - myuser -c "/myuser/MYFILES/myftpscript"

will do the trick
 
  


Reply



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
.netrc kniwor Linux - Newbie 5 12-04-2006 06:02 PM
Having an issue with inittab Zerodark Linux - Distributions 3 11-08-2005 02:35 AM
trouble logging in to ftp with .netrc laclac01 Linux - General 1 10-27-2005 01:15 PM
Konqueror FTP passive/active problem & .netrc perl21 Linux - General 0 03-17-2005 04:43 PM
How to set anscii mode in FTP using .netrc gendreau Linux - Newbie 1 08-08-2003 12:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:19 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration