Visit The New, Modern Unix Linux Community


Shell Script - If and smbclient (ftp)...help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script - If and smbclient (ftp)...help
# 1  
Shell Script - If and smbclient (ftp)...help

Hi,

So I am writting a script to copy files from Linux to windows using smbclient, I have done this a fair amount of times now. Unfortunately this time I am using a simply if statement to determine if the file exists before beginning the smbclient section.....however if I tab the smbclient command over the screen from the left to under the then/else commands it doesn't work - but it does if I leave it on the right of the screen.........It is annoying as I like formatted scripts...

This does not work:
Code:
if [ -f log* ]
        then
                echo "Files exist - transferring files" | tee -a $LOGFILE
                smbclient $servername $password -U $username >>  $LOGFILE << FTP
                prompt
                lcd $REPHOME
                cd here
                mkdir $DATESTAMP
                cd $DATESTAMP
                mput log*
                exit
                FTP
        else
                echo "Files do not exist - skipping"
fi

However this does work:
Code:
if [ -f log* ]
        then
                echo "Files exist - transferring files" | tee -a $LOGFILE
smbclient $servername $password -U $username >>  $LOGFILE << FTP
 prompt
lcd $REPHOME
cd here
mkdir $DATESTAMP
cd $DATESTAMP
mput log*
exit
FTP
        else
                echo "Files do not exist - skipping"
fi

I know it isn't the end of the world but I would like to look nice too :P
# 2  
If you only use TAB's for indent, you could use <<- FTP instead of << FTP
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 3  
thanks - these little quirks are simply difficult to find via search engine...I appreciate it
# 4  
Thanks, I would add a comment to your script stating the necessity of only using TAB's. Otherwise if someone (or yourself) needs to edit the script in future he may have a hard time finding the problem if there is so much as a single space somewhere before the label. That is why I am not too keen on this solution. As an alternative you could leave the indents for the lines in the here-document and move only the closing label all the way to the left.
# 5  
Well now I know - I will simply move the final label to the right as it is likely less experienced people may need to review the scripts.

Thanks again

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #991
Difficulty: Medium
System V was known inside Bell Labs as Unix 6.0.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a Shell Script for FTP

Hello Brothers, I am new in shell script.I need a shell script that will run in Linux Server. Script will connect to windows FTP server before connection script will check the connection from linux server to windows server, if connection is ok then show a message and get specific file and... (34 Replies)
Discussion started by: maruf
34 Replies

2. UNIX for Dummies Questions & Answers

FTP in Shell Script

Dear All, I am using FTP in a script. But when i exit from the FTP session, the commands written after EOF don't get executed. i.e. ftp <<EOF quote $login quote $password cd /tmp mget *somefile* bye EOF echo $some_variable #This last echo command or whatever piece of commands i... (10 Replies)
Discussion started by: Salman786
10 Replies

3. Shell Programming and Scripting

Help with Shell script for FTP

#!/usr/bin/ksh export filename=/grid/PowerCenter/inbound/AT/filelist.txt export SOURCE_DIR=/grid/PowerCenter/inbound/AT export ICOMS_FTP_TGT_DIR1=/dw/input/ATU/ICOM_SERV1 export ICOMS_FTP_TGT_DIR2=/dw/input/AT/ICOM_SERV2 export FILE_MASK="ATRPU_RP_ATU" echo "start" ftp_data_file() { ... (15 Replies)
Discussion started by: vsmeruga
15 Replies

4. UNIX for Dummies Questions & Answers

FTP shell script

Hi I am new in UNIX field. I don't know if I am posting in right forum or not. And I have also found out that there are so many posts about ftp shell scripting. I have tried those but actually having some problem. Well, my script should do the following..... It finds files( the filename ended... (3 Replies)
Discussion started by: abhishek_510
3 Replies

5. Shell Programming and Scripting

Use ftp is a shell script

Hi, What i would like to do is to use a shell script connect to a remote computer and download files from a specific directory. I wrote the following script. #!/bin/sh HOST='IP' USER='yourid' PASSWD='yourpw' FILE='*.txt' REMOTEPATH=/incoming/MSC/ ftp $HOST <<END_SCRIPT user $USER... (3 Replies)
Discussion started by: chriss_58
3 Replies

6. Shell Programming and Scripting

FTP using shell script

Hi All, I want to make a ftp call using a separate file where the ftp commands will reside. Please find below the details: I have 2 files Sample1.sh and Properties Properties --------- <username> <password> .... other ftp commands Sample1.sh ---------- ftp -v <servername> <... (1 Reply)
Discussion started by: pickpeters
1 Replies

7. Shell Programming and Scripting

FTP via shell script

Hi, I need to upload a file via ftp. I have given : ftp -n $HOST <<END quote user $USER quote pass $PASSWD prompt off put bus.txt quit END Its throwing a syntax error at "<<" symbol. What should be done for this ?? (2 Replies)
Discussion started by: risshanth
2 Replies

8. UNIX for Dummies Questions & Answers

Shell script for ftp

Hi ,, I am wrting a shell script to ftp a file from remote server but its giving some problem to me.can you help me in debugging this. #!/usr/bin/ksh HOST="some ip" user="user_name" passwd="password" ftp -n $HOST >>END_SCRIPT USER $user $passwd binary prompt get... (3 Replies)
Discussion started by: namishtiwari
3 Replies

9. Shell Programming and Scripting

ftp in shell script

Hi, I have to ftp to a remote machine. i have got the Ip, username and password and the file path.. I need to get the file name with out user intervention in my script.. is there any way to do this.. please help esham (2 Replies)
Discussion started by: esham
2 Replies

10. Shell Programming and Scripting

using ftp in a shell script.

I am trying to ftp some files from a certain directory, but i got an invalid command. does anybody know why i got this error? ftp -v -i -n <<SCRIPT open servername user username password cd /server/logs for file in MCWAS* do put ${file} /home/test/${file} done bye SCRIPT (2 Replies)
Discussion started by: caesarkim
2 Replies

Featured Tech Videos