Solved

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

Posted on 2006-07-07
14
352 Views
Last Modified: 2010-04-21
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



0
Comment
Question by:tmccar10
  • 6
  • 6
  • 2
14 Comments
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17064242
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
 

Author Comment

by:tmccar10
ID: 17066434
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17066613
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
 

Author Comment

by:tmccar10
ID: 17066681
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17066810
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
 

Author Comment

by:tmccar10
ID: 17072402
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17077342
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:tmccar10
ID: 17079960
Thanks-

I'll give it a try and get back to you.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 17080371
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
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 75 total points
ID: 17085772
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
 
LVL 39

Expert Comment

by:noci
ID: 17095871
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
 

Author Comment

by:tmccar10
ID: 17099912
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
 
LVL 39

Expert Comment

by:noci
ID: 17101874
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
 

Author Comment

by:tmccar10
ID: 17120914
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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now