LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   ftp in inittab -.netrc issue (https://www.linuxquestions.org/questions/linux-networking-3/ftp-in-inittab-netrc-issue-589333/)

svar 10-04-2007 03:50 AM

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?

bathory 10-04-2007 04:19 AM

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.

svar 10-04-2007 05:09 AM

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

bathory 10-04-2007 05:59 AM

Perhaps you could post the script here to see why it works as user and not as root.

svar 10-04-2007 06:21 AM

#!/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

bathory 10-04-2007 07:24 AM

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.

svar 10-04-2007 08:56 AM

Got rid of all the echos and comments. Still no luck

svar 10-04-2007 09:08 AM

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)

bathory 10-04-2007 09:56 AM

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


svar 10-04-2007 11:06 AM

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

bathory 10-04-2007 11:53 AM

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.

svar 10-10-2007 02:15 AM

Looks like
su - myuser -c "/myuser/MYFILES/myftpscript"

will do the trick


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