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? |
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.
|
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 |
Perhaps you could post the script here to see why it works as user and not as root.
|
#!/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 |
I was interested for the ftp part of the script
Quote:
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. |
Got rid of all the echos and comments. Still no luck
|
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) |
Quote:
Quote:
Code:
machine 172.16.167.5 |
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 |
Quote:
Another thing you can do is to use "su myuser" before invocing ftp in your script. |
Looks like
su - myuser -c "/myuser/MYFILES/myftpscript" will do the trick |
All times are GMT -5. The time now is 11:46 PM. |