Sponsored Content
Top Forums UNIX for Beginners Questions & Answers SFTP file check through a remote host Post 303034787 by MrShinyPants on Monday 6th of May 2019 09:33:01 AM
Old 05-06-2019
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.
At certain point if the file is not available, we must take actions and call the provider to provide the file ASAP.

host where check is located -> remote host check -> sftp host

The following script was modified from another script I found here and tried to adapt for what I need but it is not working.
when I run it, it stays running and no email is sent to me.

Code:

#!/bin/bash
icdata=data
icinp=input
ictmp=/tmp
iclog=log
key="keys/key"
file="FILE_${date}_NAME"
date=$(date +%Y%m%d)
logname="FILE_${date}_NAME.log"
file="FILE_${date}_NAME"
logdate=$(date +%Y%m%d%H%M%S);
ssh_args=( -o "StrictHostKeyChecking=no" -qni "$key" user@host )
flag="N"


#REMOVING LOG FILES OLDER THAN 30 DAYS

find $iclog -type f -name "FILE_*_NAME.log" -follow -mtime +30 -exec rm {} \; -print


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

inf_log()
{
        echo "INFO: $@"  >> $iclog/$logname
}

err()
{
        echo "No $@"  >> $iclog/$logname
        exit 1
}


#SFTP CHECK

echo Log BEGIN For $logdate>$iclog/$logname


while [ "$flag" != "Y" ]
do
ssh -T "${ssh_args[@]}"
sftp -oPort=6022 SFTP_USER@10.11.22.33 << EOF
ls -la $file
bye
EOF

if [[ -f $file ]]; then
inf_log "File is available on SFTP for tidal job to retrieve........."
ssh -T "${ssh_args[@]}"
sftp -b - -oPort=6022 SFTP_USER@10.11.22.33 <<EOF >$iclog/$logname
ls -la $file
bye
EOF
flag='Y'
else
sleep 300
fi
done

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

grep -q '$file' $comlog/$lognm

if [ $? -eq 0 ]; then
        inf_log "File is available!"
        echo "File available - No Actions needed\n"|mailx -s "FILE_${date}_NAME File check Success " me@duh.com
else
        echo "File not yet available - Please call PROVIDER\n"|mailx -s "FILE_${date}_NAME File check Failed " me@duh.com
        err " File is not Found!!! - Please call PROVIDER ASAP"
        exit 1
fi

Any suggestion or correction would be appreciated.

Thank you

Last edited by MrShinyPants; 05-06-2019 at 11:22 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Bash Script to check Remote Host Connection

Hi all, Can anyone tell/guide me how to check remote host is up/running using bash script? Thanks. Zulfiqar (5 Replies)
Discussion started by: zulfikarmd
5 Replies

2. Shell Programming and Scripting

check ssh connection to remote host

I am using KSH and I need to check whether the remote host has been configured with ssh public key. Is there any way we can check inside a script? (6 Replies)
Discussion started by: praveenbvarrier
6 Replies

3. Shell Programming and Scripting

running commands to remote host from centralized host

Gurus/Experts We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me... (6 Replies)
Discussion started by: anjum.suri
6 Replies

4. UNIX for Advanced & Expert Users

Help! How to find the local host after few ssh hops to remote host???

I do a ssh to remote host(A1) from local host(L1). I then ssh to another remote(A2) from A1. When I do a who -m from A2, I see the "connected from" as "A1". => who -m userid pts/2 2010-03-27 08:47 (A1) I want to identify who is the local host who initiated the connection to... (3 Replies)
Discussion started by: gomes1333
3 Replies

5. Shell Programming and Scripting

command to check whether the remote host is up or not

Hi, My script needs to check whether the remote host is up or not. If it is up i need to start few servers in that host or else just a notification should be sent that the remote host is down? Could someone help me out in this? Regards Arun (4 Replies)
Discussion started by: arunkumarmc
4 Replies

6. Shell Programming and Scripting

check for file existence on remote machine using sftp

Hi all, I am a beginner to shell script.Can any one please help me on the below requirement I need to check whether the file (called 3Com_Files_Delivered.txt) exists on the remote mechaine or not? if so i need to copy all the files from there to my local mechaine.Especially i am... (7 Replies)
Discussion started by: narasimha123
7 Replies

7. Shell Programming and Scripting

Reading file from remote host?

flamingo:~ jnojr$ ssh -t macbook sudo -v Password: Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo cat /etc/cma.conf | grep CMABuildNumber <CMABuildNumber>2918</CMABuildNumber> Connection to macbook closed. flamingo:~ jnojr$ ssh -t macbook sudo -k Connection to macbook... (3 Replies)
Discussion started by: jnojr
3 Replies

8. UNIX for Dummies Questions & Answers

Check port 2222 is open on a remote host

I am able to connect to a remote host using the legacy IP and port 2222. Today the remote has a new IP I am unable to connect. How to check if the remote host is blocking or if its my server is unable to connect. Err Msg : telnet: Unable to connect to remote host: Connection refused Err... (5 Replies)
Discussion started by: ITDev01
5 Replies

9. Shell Programming and Scripting

Pause processes in remote host and resume execution in another remote host

Hi, Given addresses of 2 remote machines, using a shell script is it possible to get the state of running processes in "src" stop all the processes in "src" exit out of "src" ssh into "dest" resume the state of executing processes captured in step 1 in "dest" Assumption: "src" is... (3 Replies)
Discussion started by: Saeya Darsan
3 Replies

10. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies
sftp-server(1M)                                           System Administration Commands                                           sftp-server(1M)

NAME
sftp-server - SFTP server subsystem SYNOPSIS
/usr/lib/ssh/sftp-server DESCRIPTION
sftp-server implements the server side of the SSH File Transfer Protocol as defined in the IETF draft-ietf-secsh-filexfer. sftp-server is a subsystem for sshd(1M) and must not be run directly. There are no options or config settings. To enable the sftp-server subsystem for sshd add the following to /etc/ssh/sshd_config: Subsystem sftp /usr/lib/ssh/sftp-server See sshd_config(4) for a description of the format and contents of that file. There is no relationship between the protocol used by sftp-server and the FTP protocol (RFC 959) provided by in.ftpd. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/usr/lib/sftp-server ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsshdu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
sftp(1), ssh(1), ssh-add(1), ssh-keygen(1), sshd(1M), sshd_config(4), attributes(5) To view license terms, attribution, and copyright for OpenSSH, the default path is /var/sadm/pkg/SUNWsshdr/install/copyright. If the Solaris operating environment has been installed anywhere other than the default, modify the given path to access the file at the installed location. AUTHOR
Markus Friedl SunOS 5.10 30 Jul 2003 sftp-server(1M)
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy