how to convert this script in command line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to convert this script in command line?
# 1  
Old 08-20-2012
how to convert this script in command line?

im trying to use this shellscript in one command line, but isnt working.

shellscript:
Code:
	SERVER=ftp.site.com
	USER=Foo
	PASSW=3122

	ftp -v -n $SERVER <<END_OF_SESSION
	user $USER $PASSW
	$FILETYPE
	lcd /home/foo/mywebsite
	mput *
	mput *.*
	bye
	END_OF_SESSION

Im trying a lot of commands like this below, but none works...
Code:
# server=ftp.site.com && user=Foo && passw=3122 && ftp -v -n $server << $(echo -e  "EOT\nuser $user $passw\nascii\n$FILETYPE\nlcd /home/foo/mywebsite\nmput *\nmput *.*\nbye\nEOT\n")

# 2  
Old 08-20-2012
Ok, do you mind posting the error messages you get? Use code tags if you post them, thanks.
# 3  
Old 08-20-2012
this command dont finish, keeps w/ a ">" waiting to finish the command:
Code:
# server=ftp.site.com && user=Foo && passw=3122 && ftp -v -n $server << $(echo -e  "EOT\nuser $user $passw\nascii\n$FILETYPE\nlcd /home/foo/mywebsite\nmput *\nmput *.*\nbye\nEOT\n")
>

trying other commands i got this:
Code:
# server=ftp.site.com && user=Foo && passw=3122 && ftp -v -n $server '<< EOT user $user $passw $FILETYPE lcd /home/foo/mywebsite mput * mput *.* bye EOT' echo ok
usage: -n host-name [port]
ftp>

---------- Post updated at 12:43 PM ---------- Previous update was at 12:14 PM ----------

One more try:

doing this:
Code:
echo -e "EOT\n&& user $user $passw\nascii\n$FILETYPE\nlcd /home/foo/mywebsite\nmput *\nmput *.*\nbye\nEOT"

results in this:
Code:
EOT
&& user Foo 3122
ascii

lcd /home/foo/mywebsite
mput *
mput *.*
bye
EOT

but when doing this:
Code:
server=ftp.site.com && user=Foo && passw=3122 && ftp -v -n $server << echo -e "EOT\n&& user $user $passw\nascii\n$FILETYPE\nlcd /home/foo/mywebsite\nmput *\nmput *.*\nbye\nEOT"

results this:
Code:
>

---------- Post updated at 12:46 PM ---------- Previous update was at 12:43 PM ----------

ho, just ignore the "&&" after EOT in last post, just wrong paste here
# 4  
Old 08-20-2012
Your script in post #1 has a layout problem.
The terminating string END_OF_SESSION MUST start in column one. i.e. Don't indent that line.
Also, you don't set a value for $FILETYPE . Presumably it would be ascii rather than binary .

Last edited by methyl; 08-20-2012 at 07:30 PM..
# 5  
Old 08-20-2012
The long command version does not produce valid ftp syntax.
The "EOT" and "&&" are totally surplus and should not be there.

The server=".... commands..." construct is faulty.
It's just a string assignment. It never executes any commands.
The executable bit needs backticks:
server=`".... commands..."`
Both the backticks and the double quotes are needed. It is well worth reading up on the various quote characters until you understand them. Remember that within single quotes no variables are expanded at all.

The server= version of your script does not set the file type (ascii/binary). This will cause problems with your filenames (because they are not .txt) unless you set it correctly.

When posting Shell Scripting problems, please always post what Operating System and version you are running and what Shell you are using.
There may be more modern Posix syntax for executing commands in a string assignment depending on what Shell you have.

Last edited by methyl; 08-20-2012 at 07:32 PM..
# 6  
Old 08-20-2012
sorry, i cant understand how to solve the problem.

Lets make more simple: forget about the variables, this script works:

Code:
#!/bin/bash
ftp -v -n ftp.site.com <<END_OF_SESSION
user Foo 3122
ascii
lcd /home/foo/mywebsite
mput *
mput *.*
bye
END_OF_SESSION

What i need is a way to conect to a ftp account and send some files automatically.
Now how this can be done in command line? I need to reproduce this in a command line and then put inside a system() to execute in a c program running ubuntu 12.04
# 7  
Old 08-20-2012
Try creating and testing a script, then executing that script from the C Programming Language system() call.
It will drive you nuts trying to get a one-liner to work in this situation.


Off topic.
Why?
Code:
mput *
mput *.*

If the source system is a unix system, the MSDOS 8.3 file naming convention is irrelevant. The mput * should be sufficient.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Repeat line convert upper line

HI Guys, My Input :- R3 AV44 50 0 100 100 100 R3 AV44 1 0 100 100 100 R3 AV45 50 0 100 100 100 R3 AV45 0 3 100 100 100 R3 AV45S 50 0 100 100 100 R3 AV45S 0 4 100 100 100 Output :- R3 AV44 50 0 100 100 100 1 0 100 100 100 R3 AV45 50 0 100 100 100 0 3 100 100 100 R3 AV45S 50 0... (9 Replies)
Discussion started by: pareshkp
9 Replies

2. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

convert single line output to multiple line

Hi all, I have a single line output like below echo $ips 10.26.208.28 10.26.208.26 10.26.208.27 want to convert above single line output as below format. Pls advice how to do ? 10.26.208.28 10.26.208.26 10.26.208.27 Regards Kannan (6 Replies)
Discussion started by: kamauv234
6 Replies

5. Shell Programming and Scripting

convert fields on each line to one line

Hello, I have a text file with the following fields: RecordNumber Name Email Date Notes Confirmed MailingList The problem is that each field is on a separate line. These seven fields repeat for the length of the file. What I want to do is to have a bash script or similar unitil EOF... (6 Replies)
Discussion started by: vestport
6 Replies

6. Shell Programming and Scripting

Command executes on the command line but not from script

Hello guys, I have the following commands : Command 1: sudo find "../bundlepool" -name "merchandising2.html" -print0 |xargs -0 -I {} cp "rebranding/merchandising2.html" {} Command 2: find "../bundlepool" -name "merchandising2.html" -exec cp rebranding/merchandising2.html {} \; Command 3: ... (2 Replies)
Discussion started by: ihabo01
2 Replies

7. UNIX for Dummies Questions & Answers

command line util to convert mm to inches etc?

There must be a command line utility to convert metric -> us, mm to inches etc, but I don't remember seeing it. Any suggestions? Anything in the repositories? Thx. (4 Replies)
Discussion started by: koodawg
4 Replies

8. Shell Programming and Scripting

perl script command line option driven script

could someone show me a sample command line option driven script? i want to see an easy way to write one and how i can execute it using command line options such as typing in read.pl -i <id> -c <cmds> -s <start> -e <end> would read out all the commands run by ID . from start time to... (7 Replies)
Discussion started by: kpddong
7 Replies

9. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

10. Shell Programming and Scripting

here-doc convert 2 script convert to single script?

I have my main script calling another script to retrive a "ls -alt" of a directory that's located in a remote location I'm sftping into. main.sh #!/bin/ksh getLS.sh > output.txt getLS.sh #!/bin/sh /home<..>/sftp <host@ip> <<! cd /some/dir/Log ls -alt quit ! Basically I'd like to be... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question