Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Pull a file from a remote server through a shell script Post 302188394 by sashankkrk on Wednesday 23rd of April 2008 10:54:34 AM
Old 04-23-2008
Pull a file from a remote server through a shell script

Hi,

I am writing a shell script to pull a file from a remote server (Let say its a windows based remote server). One of my criteria is to pull a file only if it is not empty.

We have done a similar script to push a file from our end to a remote server and before pushing it we check for the file size and only when it is not empty we proceed to ftp the file. This script works fine without any issues.

Here is the sample script for pushing the files to remote server.
----------------------------------------------------------------------
#!/usr/bin/ksh

"Usage: $0 <Server> <USERID> <LOCALFILEPATH> <REMOTEFILEPATH> <FTPTYPE> <FILECHECKER> <FILENAME1> <FILENAME2>...."

#FTPTYPE is either ascii or binary
#FILECHECKER is either Y or N. When Y the script has to check for file size before ftp'ing the file. It has to ftp only if the file size is > 0

#Counting the list of Files to be FTP'ed
shift 6
file_count=$#
echo "Total files to be ftped : ${file_count} "

LOCAL_FILE_LIST=$@
#Get the files that needs to be ftp'ed into a LOCAL_FILE_LIST.


#If File Checker is "Y" check if the files are empty and prepare a new file list
fl_cnt=0

if [ ${FILE_CHECKER} = "Y" ]
then
for flnm in ${LOCAL_FILE_LIST}
do
if [ -s ${flnm} ]
then
FILE_LIST=${FILE_LIST}" "${flnm}
fl_cnt=`expr ${fl_cnt} + 1`
fi
done
else
FILE_LIST=$LOCAL_FILE_LIST
fi
echo $FILE_LIST


if [ ! -z "$FILE_LIST" ]
then
echo "FTP Started"
ftp -n << EOF > $LOG_FILE
verbose
open ${SERVER}
$LOGON
$FTP_TYPE
cd ${REMOTE_FILE_PATH}
mput ${FILE_LIST}
close
bye
EOF
else
echo "Files Empty hence not FTP'd"
exit 0
fi
----------------------------------------------------------------------

Now I am having issues with my pull script, when I connect to the remote server I am not able to execute any shell commands on that server since it is a windows based. Hence I won't be able to check for file size before I pull those files.

Can anyone give some idea's/tips on how to check for file size on remote server or how to execute some shell commands on remote server?

Thanks,
Sashank
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use cURL in shell script and get most recent file from remote server using SFTP

I have been trying to implement the following shell script -- sftp to remote server get list of files in the directory sftp get the most recent listed file exit This script will be scheduled to be executed everyday using CRON or CONTROL-M and the need is to have absolutely no human... (7 Replies)
Discussion started by: toobrown1
7 Replies

2. Shell Programming and Scripting

Archive log Pull script from one server to another server

Hi all, Iam looking out for a shell script which pulls archive from Server A to Server B. And at the same time, we dont want the archives which are already pulled in Server B to be removed from Server A. Please help me on this, I have been trying on this for a quiet few time. ... (3 Replies)
Discussion started by: vivi.raghav
3 Replies

3. Shell Programming and Scripting

How to FTP the latest file, based on date, from a remote server through a shell script?

How to FTP the latest file, based on date, from a remote server through a shell script? I have four files to be FTP'ed from remote server. They are of the following format. build1_runtime_mmddyyyy.txt build2_runtime_mmddyyyy.txt build3_runtime_mmddyyyy.txt buifile_count_mmddyyyy.txt ... (9 Replies)
Discussion started by: imran_affu
9 Replies

4. Shell Programming and Scripting

Shell script to read from a file and update remote server

Its a tough one and would appreciate any guidance for a script that i am trying to develop....Again I do understand its a complicated script and help would be greatly appreciated.... Thank you 1- Need to check for a file (in a certain location on a server) every 15 minute or so if it is there... (4 Replies)
Discussion started by: aavam
4 Replies

5. Shell Programming and Scripting

Script to pull uid greater than 1000 from remote server

Hello, I am trying to get UID # greater than 1000 from all linux server, I tried this script getting this error message, someone please suggest. $for i in `cat hostlist.0709.org` ; do ssh -t $i 'awk -F':' "{ if($3 >= 1000) print $0 }" /etc/passwd ' >> output ; done $ cat output hostname1... (4 Replies)
Discussion started by: bobby320
4 Replies

6. Shell Programming and Scripting

Editing a file on remote server using shell script locally

Hi All, I have below requirements for my project: 1. Building a shell script which connects to a remote server 2. running script on local machine as user 'A' 3. connecting to server using user 'B' with password 4. login with a powerbroker role 'P' (asks for same password as 'B') on that... (1 Reply)
Discussion started by: Nishant Ladiwal
1 Replies

7. Shell Programming and Scripting

Editing a file on remote server using shell script locally

Hi Scott, My previous post was not for any school or college projects. I am currently working with a IT company (Cannot provide more details than this). I am trying to implement the below script in my day-to-day work, Apologies for the confusion in previous post :). My question remains same... (4 Replies)
Discussion started by: Nishant Ladiwal
4 Replies

8. Shell Programming and Scripting

To run a shell script in remote server from windows batch file

Hi all, i need to run a shell script on remote server. I have created file .bat file in windows server with following code, c:\Users\Desktop\putty.exe -ssh -pw password user@server ./script.sh i need to run the script.sh in my remote server Above command is not working, any... (4 Replies)
Discussion started by: rammm
4 Replies

9. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

10. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies
SIMPLEFTP(1)						    InterNetNews Documentation						      SIMPLEFTP(1)

NAME
simpleftp - Rudimentary FTP client SYNOPSIS
simpleftp url [...] DESCRIPTION
simpleftp is a Perl script that provides basic support for fetching files with FTP in a batch oriented fashion. It takes one or more FTP URLs on the command line. The file(s) will be retrieved from the remote server and placed in the current directory with the same basename as on the remote; e.g., <ftp://ftp.isc.org/pub/usenet/CONFIG/active.gz> is stored as active.gz in the current directory. The script properly understands usernames, passwords and ports specified as follows: ftp://user:password@host:port/path/file BUGS
simpleftp is an extremely poor substitute for more complete programs like the freely available wget or ncftp utilities. It was written only to provide elementary support in INN for non-interactive fetching of the files in <ftp://ftp.isc.org/pub/pgpcontrol/> or <ftp://ftp.isc.org/pub/usenet/CONFIG/> without requiring administrators to install yet another package. Its shortcomings as a general purpose program are too numerous to mention, but one that stands out is that downloaded files by simpleftp override existing files with the same name in the local directory. HISTORY
Tossed off by David C Lawrence <tale@isc.org> for InterNetNews. Rewritten to use "Net::FTP" by Julien Elie. $Id: simpleftp.pod 8357 2009-02-27 17:56:00Z iulius $ SEE ALSO
actsync(8). INN 2.5.2 2009-05-21 SIMPLEFTP(1)
All times are GMT -4. The time now is 10:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy