It'll run as a script, but not in the CRON.

I have two one-line scripts to rename a file from faint.txt -> .netrc and another to reverse the process:

mv /path/faint.txt '/path/.netrc'
mv '/path/.netrc' /path/faint.txt

Work fine as a stand-alones, but I get "/bin/sh: line 1: //proj/psl/.netrc: No such file or directory" when they run in the CRON



tmccar10Asked:
Who is Participating?
 
Duncan RoeConnect With a Mentor Software DeveloperCommented:
If you want to see verbose o/p from ftp:

#!/bin/sh
# \
exec expect -f "$0" -- "$@"
spawn bash
expect {$ }
expect_before timeout {puts \ntimed\ out;exit}
exp_send "cat t5|ftp $argv\r"
expect Password: {}
exp_send <remote password>\r
expect {$ }
exp_send exit\r

t5:

dunc
v
get .bashrc
qui

Notice line 2 - seems ftp client notices input is from a pipe
0
 
Duncan RoeSoftware DeveloperCommented:
Is it possible that cron runs the same script twice in a row rather than running them alternatively? From what you posted, you wouldn't expect that to work because the file either has one name or the other. Really could do with more detail to help here - could you post output from "crontab -l "? At a guess, if you schedule them both to run at the same time then maybe they don't always run in the order you expect.
0
 
tmccar10Author Commented:
Thanks-

Through a series of misadventures, I needed to run a script tha would rename a file to .netrc (we're not allowed to have a stored version of the file anymore--I don't know why. Run my FTP script and  then run a script to reverse the renaming.

I tried for several days, with help, and couldn't  do the user/pass thing within the FTP script to circumvent the problem.

As a result, I have my CRON run this script:
mv /ford/thishost/u/tmccar10/faint.txt '/ford/thishost/u/tmccar10/.netrc'
Then the FTP script.
Then the other script:
mv '/ford/thishost/u/tmccar10/.netrc' /ford/thishost/u/tmccar10/faint.txt

I'm getting a "file doesn't exist" message.

Thanks again
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Duncan RoeSoftware DeveloperCommented:
So you are trying to circumvent a condition of use? (COU) That could get you into trouble you know. .netrc contains a password - that is likely why you're no longer allowed to have one. You're still storing a password on your system, but in a disguised file where you hope it will stay hidden. Please understand I make no judgement on your actions - you do what you want - but if I were in your shoes I'd be discussing my needs with someone in the organisation with the authority to get the thing done "officially". Mind you I wouldn't have done that in my youth ;)
Does your cron entry try to do all 3 jobs on one line (ok) or at the same time but on different lines (not ok, as per my previous post)? Why do you put one of the pathnames in quotes?
Hang on - your scripts mv /ford/thishost/u/tmccar10/.netrc but the error you posted is //proj/psl/.netrc - why the discrepancy? In any case, the problem may lie with running youir FTP script from CRON - do check that out.
As I said before, post the relevant lines from "crontab -l"; and maybe post your FTP script as well.
You could instead use an expect script to supply ftp its password - possibly also contrary to COU
0
 
tmccar10Author Commented:
Thanks-

I know exactly what you're saying, but our "real" IT (server folks) said I should embed the logon/password in the FTP script. That's a solution?

And in anycase, I couldn't get that to work either.

I can't get to the server now. I'll post the CRON early 05:30 EDT Monday.

Sometimes it's hard for a guy who's just trying to run a website that requires uploading 50 files a day--who doesn't want to do it manually. Makes it tough to take a day off!

I'm not very comfortable with the situation.

I will take your advice, and observations under consideration.  I DO appreciate them.

Thanks again

0
 
Duncan RoeSoftware DeveloperCommented:
Here's an old script I used to use to log in to my ISP - maybe you can convert it to your needs:

#!/bin/sh
# $Id: aftp,v 1.6 1999/08/08 02:56:00 dunc Exp $
# the next line is obeyed by sh but not expect \
exec expect -f "$0" -- "$@"
puts "\$argv is $argv"
spawn ftp $argv
set timeout 60
expect \
{
  timeout {puts "timed out";exit}
  -nocase "unknown host" exit
  -nocase "connection refused" exit
  "Name"
} ;# expect
set timeout 20
exp_send anonymous\r
expect \
{
  "Service not available" exit
  "Password:" {}
} ;# expect
exp_send dunc@apex.net.au\r
interact


Usage:  "./aftp <host>"
0
 
tmccar10Author Commented:
Thanks Duncan-

As I mentioned, I'm just a nonTech guy, just trying to get through Linux/UNIX and perl etc.

I've been looking at your kind offering. I'm afraid I don't understand much (any of it)

Too bad too, this morning I wasn't able to use .netrc at all. So all my attempts at "misdirection" are useless.

Now all I want to do is be able to put the user/pass combination into my FTP script. I've been trying to get that working for over a week (see Operating_Systems/Linux/Q_21902371.html#17046986)

I closed that as I just wasn't getting anywhere with that.

I'll keep you apprised.

Thanks
0
 
Duncan RoeSoftware DeveloperCommented:
It's an expect script. Replace "anonymous" with your username and replace my old email address with your password. Then try it - you should end up with the ftp prompt and logged in. Not exactly what you want but I don't have time right now (07:45) to do anything else. Will post more in evening.
0
 
tmccar10Author Commented:
Thanks-

I'll give it a try and get back to you.
0
 
Duncan RoeSoftware DeveloperCommented:
Here's a batch-mode one. Set up the file t5 (or call it what you like but change the script to match) as follows:
line 1: <remote username>
lines 2 - n: ftp commands (get, put, cd etc)
line n+1: qui

Now run this script, with its single arg being the remote system as before:

#!/bin/sh
# \
exec expect -f "$0" -- "$@"
log_user 0
spawn bash
expect {$ }
expect_before timeout {puts \ntimed\ out;exit}
exp_send "cat t5|ftp $argv 1>/dev/null\r"
expect Password: {}
exp_send <remote password>\r
expect {$ }
exp_send exit\r

My trial t5:

dunc
get .bashrc
qui

0
 
nociSoftware EngineerCommented:
Why not using a tool like curl
(http://curl.haxx.se)

That will turn loading/storing a file on and FTP a one-liner!

like:  curl -T file ftp://host//path/to/remote -u username:password   # to store
or:   curl ftp://host//path/to/remote -O localfile -u username:password  # to fetch..
0
 
tmccar10Author Commented:
Thanks-

Having a crisis on some unrelated issues
The website said that curl is a command line tools.
If this requires a download/upload, I can't put anything on the server, so that would be out.

All you stuff is probably straight-forward from your prespective, for me the script is a challenge.

Sorry, it's taking so long to test, but between my own pitiful understanding and other commitments/'emergencies, I'm still trying to edit and run the script
0
 
nociSoftware EngineerCommented:
Command line tools can also be read as excellent scripting material.
(All shell commands you use are command line tools, chmod chown etc. )

You don;t need anything on the server. This wil act as an http client (read scriptable browsers),
ftp client (ftp filetransfers etc.) ldap client etc. etc.

Yes you need it to download to the system where your ftp with .netrc used to run.
There are many ready builts available, and offcourse the source.
If you are using *BSD or Linux chances are you allready have is on your system or at least on your installation meda.
0
 
tmccar10Author Commented:
Thanks Duncan-

I haven't actually got this working, but it looks promising and I won't be able to get to this in any serious way for another week of so and I don't want to hang you up on this.

Appreciate your help and commitment.

Thom
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.