Having a hell of atime with KSH -ftp automation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Having a hell of atime with KSH -ftp automation
# 1  
Old 05-28-2012
Tools Having a hell of atime with KSH -ftp automation

Following this thread:
Automated FTP task
I have created the following script:

Code:
#! /bin/ksh

HOST=ftp.mywebsite2.com
USER=astrocloud
PASSWD=8****

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd ~/www/gcc/cb
print -p lcd ~/www/gcc/cb
print -p binary
print -p put test.txt
print -p bye

wait
exit 0

I call this file: ./ksh_ftp.sh

The code could not be simpler. I have two identical file structures "~www/gcc/cb"
The file that I am passing from one linux to the other should reside in the same place.

The first thing is just weird. I have to call it like thus;
Code:
ksh ./ksh_ftp.sh

because otherwise I get the error:
Quote:
bad interpreter: No such file or directory
Anyways, I am lost about the error messages coming back from this.
Here is the error message that I am encountering;
Quote:
ksh ./ksh_ftp.sh
: not foundh[2]:
: not foundh[6]:
: illegal file descriptor name
Any clues? thanks
# 2  
Old 05-29-2012
Sigh....

First off: ftp was then, but you shouldn't use it at all. It is insecure because it needs you to store the password in clear text, it transmits passwords/usernames in clear text (which is open to network sniffing) and it transmits all its data without encryption. In all the data centers i work(ed in the last 10 years) ftp and telnet is absolutely positively forbidden (as in: not even allowed to be installed, much less used).

Use ssh/scp to achieve your goal and several of your problems will be gone.

Second: "HOST" and "USER" are on most system/shell combinations special variables to the shell. Log in to your system from anew and issue set and you will probably notice lines similar to these among others:

Code:
HOST=some.hostname.com
...
USER=yourloginname

Overwriting these variables with values of your own is not a good idea.


Third: The reason why you get the funny error message is that your ksh resides not where you declare it to be found in the shebang:

Code:
#!/bin/ksh

means that the ksh you want the script to use can be found in /bin. If you issue a which ksh at the commandline you probably get something else, maybe

Code:
# which ksh
/usr/bin/ksh

or whatever. Replace the /bin/ksh in the first line of your script with what you get there. From then on it should be possible to call the script by just its name instead of explicitly invoking a shell with the scripts name as parameter.

I can't find out from here what the last error means, but correct all the others first and maybe it will be gone for good anyway. If not report back and we will investigate further.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 05-29-2012
Quote:
Originally Posted by bakunin
Sigh....

Use ssh/scp to achieve your goal and several of your problems will be gone.

I think this is the right way to go. In the above example something like;
Code:
#! /bin/sh
expect -c 'spawn scp -P 22 astrocloud@www.mywebsite2.com:/home/mywebsite2/www/gcc/cb/test.txt /home/mywebsite2/www/gcc/cb/test.txt ; expect assword ; send "8*****\n" ; interact'

# 4  
Old 05-29-2012
Sorry to dissent again, but: using "expect" and hard-coding the password into the script is the same as hardcoding the password into the ftp-script.

Create private-/public-keys, exchange them and use these instead of passwords. This will cpme down to something like:

Code:
typeset srchost="www.mywebsite2.com"
typeset srcuser="astrocloud"
typeset file="/home/mywebsite2/www/gcc/cb/test.txt"

...

if [ $( scp ${srcuser}@${srchost}:${file} ${file} > /dev/null 2>&1 ; echo $? ) -eq 0 ] ; then
     echo "transmission of $file successful"
else
     echo "transmission of $file failed"
fi
...

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Web Automation in Perl/Ksh with NO additional modules

I would like to automate form filling in a remote way... i mean in the background. That form consists of 3 pages (need to be traversed by clicking on a "next" button). Form uses JavaScript as well. The scripts I have access to are perl/Unix shells I google'd and found that in perl it can be... (0 Replies)
Discussion started by: dahlia84
0 Replies

2. Shell Programming and Scripting

FTP automation with special characters in userid

Hi, i am trying to automate an ftp script which is as below.But my user id has special characters(aaa\$ifg). So it is not working correctly.Can anyone help on this?I tried providing both of them in double & singe quoted. But somehow it is not picking the "\". Also tried keeping \ before the... (3 Replies)
Discussion started by: aeroticman
3 Replies

3. Shell Programming and Scripting

FTP automation script

Hi, I have got a requirement like this. a parameterized function custFtp which will take 5 i/ps and will do the following tasks. p1) server name p2) username p3) password p4) path name of the server where the file resides p5) file name pattern the function will work like this. ... (1 Reply)
Discussion started by: ani_datta
1 Replies

4. Shell Programming and Scripting

How to track exit status of ftp automation

ftp automation code is ftp -v -n -i $host_name << EOF user $u_name $u_pass bi mput $tar_file bye EOF How to check whether the file is successfully transfered or not. Suppose the user name or password is provided wrongly then the code should track the error and ask the end user to enter... (2 Replies)
Discussion started by: Dip
2 Replies

5. UNIX for Advanced & Expert Users

FTP automation Job scheduling

Hi, I am working in Unix and Teradata fastload. I need to automate file transfer through ftp from windows path to Unix directory at a specific time, then I should call fastload scripts execution. I have got the fastload script. Entire process should be automated without any manual intervention. It... (1 Reply)
Discussion started by: SATYAPRIYA_D
1 Replies

6. Cybersecurity

FTP Automation Windows <> Unix <> Remote

Hi All, I am a newbie to unix and scripting. I need to do the following job: 1. Create a batch file in windows that will call a script in a remote unix box. 2. The script now ftp files from the Remote windows machine and get them back to the local windows. Actually, I have written the script... (3 Replies)
Discussion started by: Ankur
3 Replies

7. Filesystems, Disks and Memory

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

8. UNIX Desktop Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

9. UNIX for Dummies Questions & Answers

Urgent FTP script automation

Hi guys, Here is my requirement for ftp script that i have to automate in unix using shell script: 1) Find the files that atre created one week from the present day. 2) ftp them to the backup server. 3) At the end of the month make a new directory on my backup server with the new month(eg:Once... (1 Reply)
Discussion started by: koduri0475
1 Replies

10. UNIX for Dummies Questions & Answers

Automation of telnet and ftp

I have a basic query. I use telnet and ftp very frequently. I want to do it without spending time in typing username and password everytime. I know that if I have .netrc file which contains server address, username, pasword, then just typing ftp will conect to that server with that username and... (10 Replies)
Discussion started by: asutoshch
10 Replies
Login or Register to Ask a Question