Sponsored Content
Top Forums Shell Programming and Scripting check for file existence on remote machine using sftp Post 302404676 by narasimha123 on Wednesday 17th of March 2010 03:16:42 AM
Old 03-17-2010
hi All,
Thanks for all your thoughts on this.Finally i am able to code a program which ftp's the files from remote machine to my local machine.But a part from this i need to add a process here i am giving full details .please guide me on this.

i need to add a process to the below existing script which has to poll every 5 minutes until 12 P.M from 5 A.M .How can i add this to the below script.Please advice me.

every my script will be triggerd at 5 A.M through scheduler.

Code:
comdta=/var/opt/etl/datsrc/3com/data
cominp=/var/opt/etl/datsrc/3com/input
comtmp=/var/opt/etl/datsrc/3com/temp
comlog=/var/opt/etl/datsrc/3com/log
logdate=`date +%Y%m%d%H%M%S`;
lognm="3com_FTP_$logdate.log"
trgr_file="3Com_Files_Delivered.txt"
infile="3Com_*"
maillist=`eval echo $TCOM_MAIL_LIST`
flag="N"


####################################################################
#
#REMOVING LOG FILES OLDER THAN 30 DAYS
#
####################################################################

find $comlog -type f -name '3com_FTP_*.log' -follow -mtime +30 -exec rm {} \; -print


#----Log Errors in Log File---------#

inf_log()
{
	echo "INFO: $@"  >> $comlog/$lognm
}

err()
{
	echo "ERROR: $@"  >> $comlog/$lognm
	exit 1
}


#######################################################################
#
# FTP PROCESS To check the existence of the trigger file every 5 min
# and if exist move all the input files from SFTP Server to 3com folder
#
#######################################################################


cd $cominp


echo Log BEGIN For $logdate>$comlog/$lognm


while [ "$flag" != "Y" ]
do
sftp -b - $TCOM_SFTP_FILES <<EOF >$comlog/$lognm
get /$trgr_file
bye
EOF

if [[ -f $trgr_file ]]; then
inf_log "Trigger File Exist on SFTP Server........."
inf_log "Copying 3Com Files Started.........."
sftp -b - $TCOM_SFTP_FILES <<EOF >$comlog/$lognm
mget /$infile
bye
EOF
flag='Y'
else
sleep 300
fi
done

#--------Now copying Plan,Pipeline,Forecast file(s) from input to data directory-------#

cp 3Com_Plan* $comdta
cp 3Com_Pipeline* $comdta
cp 3Com_Forecast* $comdta


#-------Mail SFTP status----------------------------#

grep -q 'Fetching' $comlog/$lognm

if [ $? -eq 0 ]; then
	inf_log "SFTP File Transfer Success!!!"
else
	echo "SFTP File Trasnsfer Failed\n"|mailx -s "3COM File Transfer Failed -ERROR" $maillist
	err " SFTP file transfer Failed - File is not Found!!!"
	exit 1
fi



#-------Remove input file(s) from SFTP Server-------#

sftp -b - $TCOM_SFTP_FILES <<EOF >>$comlog/$lognm
cd /
rm $infile
quit
EOF



#-------Notifying SFTP File(s) Removal Status-------#

grep -q 'not found' $comlog/$lognm
if [ $? -eq 0 ]; then
	err " Removal of 3Com File(s) from SFTP Box Failed!!!"
else
	inf_log " Removal of 3Com File(s) from SFTP Box is Success!!!"
	exit 0
fi


THANKS
narasimharao

Last edited by pludi; 03-17-2010 at 05:42 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. SCO

Need Script to check whether user exists in the remote machine

Hi All, I am new to shell scripting. Can someone let me know, how to check whether the user exists in the remote system? I am building a new unix box and before I proceed installing the appliation , I want to check whether the required users are created in the system . how to do this ?... (1 Reply)
Discussion started by: Srini75
1 Replies

2. Shell Programming and Scripting

check for a file on a remote machine

Hi, Can someone tell me how to check if a file exists on a remote machine using rexec command?I'm using ksh. Thanks (3 Replies)
Discussion started by: Sheema
3 Replies

3. Red Hat

To find the LATEST file from a dir on REMOTE machine and SCP to local machine?

Hi All, URGENT - Please help me form a scipt for this: I need the LATEST file from a dir on REMOTE machine to be SCP'd to a dir on local machine. (and I need to execute this from local server) I know that the below cmd is used to find the LATEST file from a dir. But this command is not... (3 Replies)
Discussion started by: me_ub
3 Replies

4. Programming

Check if user logged into remote machine via C++ / Java

Hi, I have a program running on HP-UX and it must checkwhether a user has already logged-in to another machine. The hostname of the other machine is known when the check has to be made. Is there a way which this can be accomplished using C++ or Java? If not I could parse the output of a... (6 Replies)
Discussion started by: johnmmcparland
6 Replies

5. Shell Programming and Scripting

check web server running on local and on remote machine

Hi , How to check whether web server is running from remote machine How to check whether web server is running on web server itself Can any one help me soon (1 Reply)
Discussion started by: satheeshkr_cse
1 Replies

6. Shell Programming and Scripting

Check file exists on remote machine.

I am haveing one script haveing one issue with this could any one can reply soon it is very urgent. :p if ssh hcp_ftp@$1 'ls '$2/stop.txt' 1>&2 2>/dev/null'; then exit 1; else scp -p hcp_ftp@$1:$2/VAT*.dat $3 <<EOF EOF cd $3 pwd echo 'About to find file' SOURCE_FILE=$(ls -rt VAT*.dat|tail... (2 Replies)
Discussion started by: marpadga18
2 Replies

7. Ubuntu

I want to upload file on remote machine in noninteractive mode through SFTP

Hi All, I want to upload file through SFTP in non interactive mode on remote server. please tell me what will have to do in oreder to do SFTP . (1 Reply)
Discussion started by: kulbhushan
1 Replies

8. Shell Programming and Scripting

Polling for existence of file on remote host

I am polling a file on remote host. I have this code that works, but can't explain why it works. while user@remote.no-exist.com 'ls /user/app1/.done'` ] do echo Sleeping for 5 secs sleep 5; done This code works in the way that when the .done file exists on the remote host, the script... (1 Reply)
Discussion started by: starlatch
1 Replies

9. Solaris

unable to sftp to a remote server from Unix machine

Hi, I get the below when i try to sftp to a remote server $ export SOCKS5C_CONFIG=~/.ssh/socks5c.conf $ sftp -v -s /usr/lib/sftp-server -oPort=2222 -oIdentityFile=~/.ssh/wm_privat> Connecting to ftp01.wmgruppe.de... Sun_SSH_1.1.3, SSH protocols 1.5/2.0, OpenSSL 0x0090704f debug1:... (1 Reply)
Discussion started by: Bigbee
1 Replies

10. UNIX for Beginners Questions & Answers

SFTP file check through a remote host

Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know. I'm trying to build a script to check a file in an sftp server through a remote server. The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
Discussion started by: MrShinyPants
4 Replies
CHECKBASHISMS(1)					      General Commands Manual						  CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 08:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy