Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP PROBLEM 1

Status
Not open for further replies.

johny2K

Technical User
Dec 19, 2001
184
CA
hi,

can someone debug this script? when i run it manually, line-by-line it seems to work, but running this script gives me "Failed to open file." "STRAIN" is numeric value (041505) that needs to be joined by 'RESULT.01' as an input file to get.

#!/bin/ksh
HOST='192.168.68.52'
USER='dba'
PASSWD='dbadmin'
SOURCE_DIR='/home/testing'
TARGET_DIR='/home/final'
FILE='echo | cat FILE2.log'

cp /dev/null FILE.log
cp /dev/null FILE2.log
echo | cat STRAIN >> FILE.log
echo 'RESULT.01' >> FILE.log
# sleep 2
sed '$!N;s/\n//' FILE.log >> FILE2.log

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SOURCE_DIR
get $FILE
quit

END_SCRIPT
exit 0
 
Something like this ?
#!/bin/ksh
HOST='192.168.68.52'
USER='dba'
PASSWD='dbadmin'
SOURCE_DIR='/home/testing'
TARGET_DIR='/home/final'
FILE="$(<STRAIN)RESULT.01"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SOURCE_DIR
get $FILE
quit
END_SCRIPT

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV - line FILE="$(<STRAIN)RESULT.01", works perfect! thanks. i forgot to mention the use of "TARGET_DIR".

after dowloading, i have to change the "CASE" of the file's "RESULT.01" to small-case "result.01" as some user will catch it as:

"$(<STRAIN)result.01. i tried this but won't work:

#!/bin/ksh
HOST='192.168.68.52'
USER='dba'
PASSWD='dbadmin'
SOURCE_DIR='/home/testing'
TARGET_DIR='/home/final'
FILE="$(<STRAIN)RESULT.01"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SOURCE_DIR
get $FILE
quit
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"
END_SCRIPT
 
...
quit
END_SCRIPT
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
long overdue for PHV ...... thank you
 
i'm just wondering what causing it to fail under crontab?

/home/terminator/get-file[11]: STRAIN: cannot open


*************************************************
Cron: The previous message is the standard output
and standard error of the following crontab command:

/home/terminator/get-file

NOTE:

-rw-r--r-- 1 user user 7 Jun 21 00:01 STRAIN

even changed it to:

-rwxrwxrwx 1 user user 7 Jun 21 00:01 STRAIN
 
Are you sure the cron job is launched with the right home directory ?
You may consider add a cd command on top of the script.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This is how the script looks like now, but showing same results under crontab result:

#!/bin/ksh
HOST='192.168.68.52'
USER='dba'
PASSWD='dbadmin'
SOURCE_DIR='/home/testing'
TARGET_DIR='/home/final'
cd /home/terminator
FILE="$(<STRAIN)RESULT.01"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SOURCE_DIR
get $FILE
quit
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"
END_SCRIPT

NOTE: /home/terminator is where this script reside. i'm thinking about permission but i even used "root" crontab and has same result.

 
And you have a file named /home/terminator/STRAIN ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
yes... on the same directory as the script.

i'm puzzled coz it works perfectly once run under command prompt.
 
Thank you PHV - it works great now :) it should be a closed call now :)

#!/bin/ksh
HOST='192.168.68.52'
USER='dba'
PASSWD='dbadmin'
SOURCE_DIR='/home/testing'
TARGET_DIR='/home/final'
cd /home/terminator -> mistakenly misplaced after next line
FILE="$(<STRAIN)RESULT.01"
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $SOURCE_DIR
get $FILE
quit
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"
END_SCRIPT
 
I'd replace this:
quit
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"
END_SCRIPT
By this:
quit
END_SCRIPT
mv $FILE $TARGET_DIR/"$(<STRAIN)result.01"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top